Tag Info

New answers tagged

3

You can try creating a .desktop file in /usr/share/applications (or ~/.local/share/applications, if only for one user) like explained here (works for other desktops too). To link this program to .asm files you first have to create a mimetype for .asm files. In order to do so you have to add/modify the line text/x-asm asm in ...


4

This should work: loadval=$(sar -u 1 10 | awk '{print 100-$8}')


1

Booting from a live CD is booting nothing else but what is on the CD. We won't be able to control this from our existing installation on our hard drive because our computer will not access it during boot. We may however create a customized live session to include all we need there: How to customize the Ubuntu Live CD? On a live session desktop icons will ...


0

You can write a command script with editor vi or vim. Files shall be executable. Make them with "chmod a+x File" Put your scripy in directory where system path is located. In Terminal you find path with : echo $PATH.


3

You can use on_ac_power to run a script when the power supply is turned on or off. Try the following in a terminal. $ on_ac_power $ echo $? 0 ## Laptop on ac power $ on_ac_power $ echo $? 1 ## Laptop on battery (not on ac power) Based on this you can make your script as, #!/bin/bash while true do if on_ac_power; then ...


2

The tutorial step 2 asked to create a new user: hduser. So if you decided to adopt this username for the Hadoop user, the path of start-all.sh should be: cd /home/hduser/hadoop/bin/ start-all.sh Or if installed system-wide: /usr/lib/hadoop/bin/


1

Wile using HEREDOC delimiter, there should not be any lagging or trailing spaces and the delimiter should be the only word on the line. I this example, I had a space after EOF which was causing all the issue. Script is working as expected after removing that lagging space!! Credit for this answers goes to the user Carlos Campderrós on StackOverflow. Just ...


4

This is fairly straightforward with recent versions of bash by using globbing and arrays, which is what I assume you mean by tables. First create some test files: path=/some/where touch $path/{a,b,c}_suffix.txt Here is an example that puts all files ending in _suffix.txt into the files array: files=("$path"/*_suffix.txt) To iterate over them you can ...


2

What you call a table is usually called an array or a map. In bash, to create such an array: path="/home/user/Documents" suffix="_suffix.txt" files=( "$path"/*"$suffix" ) The * is a wildcard, which is expanded by the shell to all matching filenames (that have $path before it and $suffix after). The brackets (()) convert the expanded filenames into an ...


0

I'm surprised at the results I'm seeing for searching for a well-defined and supported Ubuntu "first boot" hook. Seems like the Red Hat / Fedora / CentOS crowd has had this nailed for over a decade. The closest Ubuntu equivalent seems to be oem-config-firstboot. The idea of simply performing an rm $0 will work. But, technically there are some interesting ...


1

You can use wget as shown here: Downloading an Entire Web Site with wget Sep 05, 2008 By Dashamir Hoxha in HOW-TOs If you ever need to download an entire Web site, perhaps for off-line viewing, wget can do the job—for example: $ wget \ --recursive \ --no-clobber \ --page-requisites \ --html-extension \ ...


2

You missed a space between [[ and $REPLY: while [[$REPLY != 0 ]]; do should be while [[ $REPLY != 0 ]]; do


0

I'm no expert but I think the problem was the open input stream. This code does the trick: ### Actual Work ### if [[ $manual == 0 ]]; then # Read the servers from the config file. while read line; do # Read line by line. arguments="$arguments $line" # Build a string for $arguments out of the ...


5

The difference is that your current working directory would have to contain the script that you'd like to execute. In this case, the dot stands for current directory, the slash does it's normal delimiter job, then the name of the script follows. If a script was in the directory above your current working directory you could execute it using ../ It's ...


8

If the scripts directory isn't in your PATH, and . (the current directory) is not in the PATH either, you can run the script using ./ as shown below ./script_name.sh Use the script file name to run it either by using it’s relative path or absolute path as shown below: cd /home/user ./script_name.sh OR /home/user/script_name.sh


0

This can be done using a script crossfade_cat.sh it was answered here http://stackoverflow.com/questions/28652490/cross-fading-several-audio-files-using-sox/28670099#28670099 And using this script to call it crossfade_dur=1 i=0 for file in *.wav do i=$((i+1)) if [ $i -eq 1 ] then cp $file mix.wav else crossfade_cat.sh ...


0

Or just from bash: MYPID=$(pidof target) ; zenity -- info --text "Process $MYPID waiting" & wait $MYPID ; killall zenity Note that wait requires the process to be a child of the current shell; you could use your original version instead.


1

Using Zenity What can relatively easy be done is to: generate a Zenity message to mention your script is waiting for a pid to appear. The window will be automatically closed if the pid appears in the output of ps -p <pid>, ps -e or any other ps command, run by the script. Example Below is the procedure how it can be done. I am using python in ...


1

First, glen jackman was close: your script is using CR-LF (\r\n) line endings. For example, I recreated your script with CRLF line endings manually: $ cat foo.sh #!/bin/bash echo "Deleting: " $1 grep -lr $1 foo.txt | xargs echo echo "Done" $ file foo.sh foo.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators $ sh foo.sh ...


0

Since this is a very high rated question on google, I'll add the steps I did to re-enable beep in both console and X11: - For the Linux Console (CTRL+ALT+F1...F6): Why it does not work by default: As already answered, the pcsprk kernel driver for the PC Speaker is blacklisted in Ubuntu. Temporarily enable until reboot: sudo modprobe pcsprk ...


0

If you have to run your script with sudo, you can still run some commands as a normal user using: sudo -u $SUDO_USER <command> If you run the following script with sudo: #!/bin/bash whoami sudo -u $SUDO_USER whoami It will output: root sylvain


2

See the manual for sudo: -k [command] When used alone, the -k (kill) option to sudo invalidates the user's cached credentials. The next time sudo is run a password will be required. So put a sudo -k before every sudo command you want to re-ask for a password. Or behind every command where you want the next commands not to be sudo. By the ...


0

sudo apt-get incron to install the "inotify cron" system http://inotify.aiken.cz/?section=incron&page=about&lang=en echo $USER | sudo tee --append /etc/incron.allow to allow you to play the game. icrontab -e to create an event to watch. It opens nano. Enter your heart's desire. e.g., /home/nodak/watched_dir IN_ACCESS ...


1

If you want to use Bash instead Python: #!/bin/bash folder=$1 while true; do command=$(wmctrl -l | grep -o "$folder") if [[ "$folder" == "$command" ]]; then ./myscript.sh break; fi done Edit: I changed a script so you can run it with the following command: bash folderwatch.sh BackupSSD Also, you can make a script ...


4

I assume you need to know the (clock-) time the folder is opened in e.g. nautilus, not the time it takes to access the folder. Using the window list You can get the window list from the command wmctrl -l, and see if the folder's name occurs in the list. The loop to check would however take at least a split second to notice the folder is opened. You'd have ...


-1

In bash scripting you need to compare two variable with below method. if [ "var1" != "var2" ]; then Do something fi; Spaces are important


0

If your shell is bash, one way could be to use commands in ~/.bash_logout. From man bash: When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists. SSH runs a login shell, so when it exits .bash_logout should be run. You can check whether it is an SSH session by testing the value of the SSH_TTY variable. So ...


4

Consider this error message: install.sh: 4: install.sh: source: not found That means that the script is not being executed by bash. This error likely comes from dash which is the default shell under Ubuntu. Try running your script as: bash /path/to/install.sh More Observe the line: sh kvminstall.sh This starts kvminstall.sh using the default ...


-1

One way, that I wouldn't generally recommend, is to read in the password yourself, and use sudo's -S option to pass the password as and when needed: #! /bin/bash read -rsp 'Enter your password: ' password git clone ... sudo -S apt-get install foo -y <<<"$password" From man sudo: -S, --stdin Write the prompt to the standard error ...


5

Since you have sudo access, create a sudoers file for yourself, then delete it when the script is done: # grant this user access to the sudo commands without passwords # add all required cmds to the CMDS alias sudo tee /etc/sudoers.d/$USER <<END $USER $(hostname) = NOPASSWD: /usr/bin/apt-get, /usr/sbin/adduser, /bin/rm, ... END # your script goes ...


0

I just followed this answer from How to Setup a root cron Job Properly: If you want to run a script as a normal user: crontab -e And add the line: 07,37 * * * * /usr/bin/tunlrupdate.sh If you want to run your script as root: sudo crontab -e And add the same line: 07,37 * * * * /usr/bin/tunlrupdate.sh As the user and it worked ...


0

Don't forget that these cron scripts are run as root, which means that for example the home directory refers to root's home directory, and so on. Since your script asks for a password, you probably need to run it with root privileges so you can't just create the usual .anacron/cron.daily and put your script in there, you have to use /etc/cron.daily so it ...


2

As the permission of the file is b.sh is -rw------- b.sh, there is no execute bit set for user, group or others. If you want to execute the file as 'userB' then running the following will do: sudo chmod 605 /home/userA/Documents/b.sh


3

Your script lacks read and execute permissions for user B. Do: chmod og+rx b.sh


1

You can use Arronax to create a starter for your script and save it into $HOME/.config/autostart/ (that's "User Autostart Folder" in the "Standard Folders" list in the lower left of the "Save File" dialog)


2

Try this: gawk -F, ' # spawns nslookup as a coprocess, passes the IP into its stdin # then reads the output of the coprocess to find the hostname function get_name(ip, line, name) { name = "UNRESOLVED" print ip |& "nslookup" close("nslookup", "to") while (("nslookup" |& getline line) > 0) { ...


6

As other people said before me: Don't parse the output of ls! (see http://www.smallo.ruhr.de/award.html#ls) Why not simply: stat --printf='%y\t%n\n' -- * If you want to do something with each file name and time stamp, read the output of stat like this: stat --printf='%y\t%n\0' -- * | \ while IFS=$'\t' read -rd '' timestamp i; do echo "filename: ...


4

Do not parse the output of ls, use a glob: for i in * ; do Also, quote the variables that might contain spaces: timestamp=$(stat -c %y "$i")


1

In a single (flat) directory If all files are in one and the same directory, the script below should do the job. #!/usr/bin/env python3 import os import sys dr = sys.argv[1]; ids = ("_3800.mp4", "_8000.mp4") checklist = [f[:-9] for f in os.listdir(dr) if f[-9:] in (ids)] for f in [f for f in set(checklist) if checklist.count(f) != 1]: ...


1

Script to reorganize photos into /year/month directories The script below does the following: It determines the month the picture was taken Inside your targeted directory, it creates (if necessary) sub directories per year (if photos were found) Inside these year directories, it creates sub directories per month If the script is unable to find an ...


3

Zenity can be used to make a GUI file picker, using the --file-selection option. For a single file, this is sufficient: #! /bin/bash file="$(zenity --title "Pick a file" --file-selection)" do something with "$file" Where it gets tricky is handling multiple files. There are only two characters not allowed in filenames: the ASCII NULL and /. /, of ...


0

After some further research, I have discovered a much more proper and reliable way of doing this. First, you add an LSB header to your script that defines the runlevel settings you want to use and then put an executable version of the script in /etc/init.d. After doing this, you can use the update-rc.d command to add the script to your desired runlevels. ...


4

Go to a terminal by pressing Ctrl+Alt+T and type md bin Go to the dash type gedit and press Enter Copy paste the following text into it: #!/bin/bash # # This script deletes video files of 8000 bps if and only if the 3800 bps file exists # as set in http://askubuntu.com/questions/581400/how-to-delete-files-selected-by-rules # # ...



Top 50 recent answers are included