Tag Info

New answers tagged

2

I'd suggest using a shell here document in this case #!/bin/bash function myfun { cat << EOF | gnuplot -p plot "$1" using $2:$3 EOF } Then myfun sourcefile 1 3


2

I really do not know what kind of script is that one. Where did you find it? .../bash/gnuplot seems that someone is getting really confused. But if you have the file with the data, call it sourcefile, with the structure whatever x-data y-data whatever x-data y-data whatever x-data y-data you can have a scatter plot of column 3 versus column 2 ...


2

If your goal is to pass a variable to awk in order to use it within the script, you can use awk with the -v option: hey=$(awk -v MYN=$MYN 'NR==MYN' x)


2

I see your problem, you're using single quotes. They won't allow the Bash variable $MYN to expand. You can complicate things by telling awk a new variable, or because it's so simple, you can just switch to double-quotes: awk "NR==$MYN" x I'd have used sed but I can't see any obvious issues with your logic MYN=4 sed "${MYN}q;d" x >> y It seems ...


0

Using awk to create a SQL query: find . -type f -maxdepth 1 -exec awk -F_ '{print "UPDATE table SET service_id=\""$1"\", mac_adress=\""$2"\" WHERE id=<your_primary_key>;"}' {} \; Example output: UPDATE table SET service_id="TBBN027162G", mac_adress="38d8-2f08-0c40" WHERE id=<your_primary_key>; UPDATE table SET service_id="TBBN027605G", ...


1

In python In a one- (long-) liner: python3 -c 'data = [l.split("_") for l in open("f").read().splitlines()]; [print("service_id: "+d[0]+",", "mac_address: "+d[1]) for d in data]' where 'f' is the sourcefile, between (double) quotes. Output: service_id: TBBN027162G mac_adrres: 38d8-2f08-0c40 service_id: TBBN027605G mac_adrres: 38d8-2f08-1518 service_id: ...


0

sudo mount /dev/sXX && rsync whatever I have tested and i receive email errors if mount fails. Therefore this uses crontab/rsync and notifies me of failed mounts via email. Not really a script, but hey, why do extra work, K.I.S.S. !


3

Since you mention you solved the problem for your specific situation, below a solution for general purpose. Thanks to xdotool's --sync option, it works pretty reliable in the tests I ran; I could "send" commands to specific terminal windows and it ran perfectly without an exception. How it works in practice The solution exists from a script, which can be ...


1

If your script is in /home/student/Scripts/ then start it from there. cd /home/student/Scripts ./adduser.sh Or with path sh /home/student/Scripts/adduser.sh I do not know what the script is. It probably will need sudo.


1

You can use parameter expansion and an extended glob to "normalize" the whitespace. # enable extended globs so that +([[:space:]]) matches one or more whitespace shopt -s extglob # replace all occurances of one or more whitespace with a single space prvar=${prvar//+([[:space:]])/ } echo "blah blah blah $prvar blah blah" This allows you to safely quote ...


1

You dont have to quote (") everything in echo. You can have many strings. Simply dont quote prvar: echo "blah blah blah" $prvar In the shell (which is expanding $prvar for you before echo even sees it), spaces inside quotes (") are preserved, but spaces and tabs outside quotes are reduced to one space. eg echo "a b" d e a ...


1

Here's a very simple bash script. Make it executable with chmod +x and add as custom startup application to run this continuously on every login. Since I've mentioned aplay, this should work in command line, not just gui. My current laptop doesn't have sound,so i had to test everything with notify-send . Feel free to adapt the script as necessary. ...


0

TL;DR: it's ok, really What you have there is exactly the response that sudo apt-get install some-software-name gives. It's very common to use apt-get on Ubuntu as an alternative to Software Center, which is a bit slow. I don't understand why you are running some script, when you can just use sudo apt-get install package-name-1 package-name-2 package-name-3 ...


1

Assuming, your script has the name sound_notifier and it's placed in /usr/bin: sudo chmod +x /usr/bin/sound_notifier Create a script /etc/network/if-up.d/start_sound_notifier sudo nano /etc/network/if-up.d/start_sound_notifier add the code below #!/bin/sh if [ "$METHOD" = loopback ]; then exit 0 fi # Only run from ifup. # if [ "$MODE" != start ]; ...


0

Try this: sshpass -p '[MYPASSWORD]' ssh [USER]@[HOST] 'bash -s' < PATH/TO/LOCALSCRIPT It seems that command is needed in the case when there is no terminal at all. (found here)


3

Take a look at http://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/ then just write a sh script which you chmod +x so that you can execute it then just use the script to launch the other script.


-1

You could try a simpler one like this: 11| grep trans.sh -xrwxr-xr-x 1 %root% %root% and it might work fine this way.


1

TL;DR Start your script with trans.sh, that's the full name. Explanation rwxr-xr-x 1 root root 131 Jun 27 12:30 trans.sh* rwx The owner root has read rights rwx The owner root has write rights rwx The owner root has executable rights rwxr-xr-x 1 root root 131 Jun 27 12:30 trans.sh* r-x The group root has read rights r-x The ...


1

OK couple of points: You don't need the /usr/bin added. Shell will find wmctrl by itself. That's for very specific cases that may involve portability. Add ampersand at the end of firefox command. The script will proceed only if the previous command exits. Since firefox doesn't exit, the script waits for it. As Oli pointed out, better way is to use class ...


0

It seems likely that the firefox command would block the script from progressing until it exited. Simply push it into the background and your script can progress: firefox http://www.google.de & On a tangential note, you might also want to look at the -no-remote for Firefox. This will stop the command interacting with any existing Firefox instances in ...


0

Try the following code:- nohup /usr/bin/chromium-browser --disable-gpu --enable-offline-auto-reload -- enable-offline-auto-reload-visible-only --app=chrome-extension://jbnkffmindojffecdhbbmekbmkkfpmjd/foreground.html & Is this what you wanted? Did it work for you?


1

The problem is that ./program -a asdf's output gets buffered when run in the pipeline, and that any output it's going to sit within the buffer until this one gets full. You can control a command's output buffering using stdbuf; in particular, to run ./program -a asdf with an unbuffered stdout: stdbuf -o0 ./program -a asdf So that your buffered pipeline ...


1

Run the command: sudo visudo Now go to the entry of %sudo %sudo ALL=(ALL:ALL) ALL and replace it with: %sudo ALL=(ALL) NOPASSWD:/usr/bin/docker this will affect all sudo users. If you just want to do that option for one specific user"must have sudo permissions": user ALL=(ALL) NOPASSWD:/usr/bin/docker Now save and exit. To be sure that ...


2

To prevent corrupting the /etc/sudoers file, always use the visudo command. If you don't like the default editor set the EDITOR environment variable to your desired one. Put your user specification line as the last line in the sudoers file. Update: Please see: Adding NOPASSWD in /etc/sudoers doesn't work


1

You don't put the user who's executing the job in a cron job line. You can see the correct format by running man 5 crontab in a terminal. Each user has their own separate crontab (cron job table). To edit agile's crontab, open a terminal and run: su agile crontab -e This will open agile's crontab in a text editor. Insert the cron job line you have above ...


3

As the error messages are normally shown on STDERR (File descriptor 2), you need to redirect both the STDOUT and STDERR to tee: ./some_app -i "$INDEX" |& tee "$LOG" When you do ./some_app -i $INDEX | tee $LOG you are only redirecting the STDOUT to tee. |& will cause both the STDOUT and STDERR to be redirected. If you cant to redirect only the ...


9

The fatal error is probably coming out in STDERR (2), not STDOUT (1). You can redirect STDERR into STDOUT with 2>&1 and then the pipe should capture it too. ./some_app -i $INDEX 2>&1 | tee $LOG If you have buffering issues on top, you could force it into an unbuffered state: stdbuf -o0 ./some_app -i $INDEX 2>&1 | tee $LOG


0

Try putting the actual script under /etc/init.d/jleaf-app instead of having a symlink to your home directory.


1

The process you are looking for is notify-osd. You can kill it by either the command: pkill notify-osd or by its pid: kill $(ps -e | grep notify-osd | awk '{ print $1 }') or, even better, as suggested by @kos (thanks!), using pgrep: kill $(pgrep ^notify-osd$)


0

Firstly you're missing a # in the sha-bang. Secondly I would recommend putting the entire path of your agile executable and thirdly I would reformat the file as it seem to be a mess. I would also suggest checking other log files as there are many different reasons why that mail wasnt sent and try adding logging support to that script if anything on it ...


1

Here is a static analysis for your shell script: 1 #!/bin/bash 2 3 a=`netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | grep -v '1 ' | grep -v '2 ' | grep -v '3 ' | grep -v '1.1.1.1' | grep -v '1.2.2.2' | grep -v '127.0.0.1' | grep -v '127.0.1.'` ^––SC2006 Use $(..) instead of legacy `..`. 4 ip=`netstat -ntu ...


3

Variable names in bash are case-sensitive; you have no $IP variable set (although you have an $ip variable set): grep $IP expands to grep, which leads to the grep error and to the kill error. Change this line p=`ps ax | grep $IP | grep -v grep | grep -v /usr/sbin | awk '{print $1}'` to this one p=`ps ax | grep $ip | grep -v grep | grep -v /usr/sbin | ...


1

xdg-open is actually a shell script (on my system). It uses heuristics to guess what your browser is. You could see what it is trying to do by running it with from within the script with sh -x xdg-open http://localhost:9000/ >&/tmp/errors Look in /tmp/errors for any failure messages. You may also simply replace xdg-open by the name of your browser, ...


1

It's a very short answer, start node server.js as background process: #!/bin/bash node server.js & xdg-open http://localhost:9000/


-1

disown is a separate command you have run it on it's own. The best way to do so is to put it in an extra line: #!/bin/bash /usr/bin/chromium-browser --disable-gpu --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --app=chrome-extension://jbnkffmindojffecdhbbmekbmkkfpmjd/foreground.html & disown


0

I have found the start-all.sh file on /hadoop-x.x.x/sbin directory. path/to/hadoop-x.x.x/sbin/start-all.sh where hadoop-x.x.x is a directory which was created on extracting the downloaded the hadoop.tar.gz file. If you initiate the file, it would show $ bash /home/foo/hadoop-2.7.0/sbin/start-all.sh This script is Deprecated. Instead use start-dfs.sh and ...


0

I wish people would stop doing: wget | bash. It's just silly, and has unintended effects like the one here. You have bash, so make use of its features. In particular, process substitution: bash <(wget -O - http://serverip/subfolder/script)


0

You need to save the wget output into a file and look at the html to see how they are implementing the timeout and redirect. There are several techniques that might be being used. For example, the simplest is a line like this in the head of the html: <meta http-equiv="refresh" content="2;url=http://newurl/"> This makes a browser go to the new url ...


1

You probably just need to stop apt-get from greedily reading the standard input. Do this by redirecting stdin to /dev/null, a file that returns eof to reads. Eg: apt-get -y --force-yes install ... </dev/null


5

Take advantage of the fact that the path is searched in order for applications. roadmr@blackdog:~$ which firefox /usr/bin/firefox roadmr@blackdog:~$ echo $PATH /home/roadmr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games So when you try to run "firefox" it will be searched for in those directories, it's ...


1

A logout in a script doesn't affect anything, since logout only works for login shells, and scripts aren't typically run as login shells. It seems to me that you're logging on via SSH (or something), running as another user and immediately logging out. In that case, just source the script, so that the commands are run in your current shell. Then, logout ...


2

Perhaps all you want to do is: exec ./test.sh This replaces your current shell process by the script, so that when it finishes there is nothing left to run.


2

Typically, to run a command as root, sudo is sufficient. #!/bin/bash echo test sudo whoami If you insist on using su,for whatever reason, you can use -c flag : #!/bin/bash echo test sudo su -c whoami And here's the result, same in both cases: $ ./test.sh ...


0

Piping to at works just fine. For example, the following works fine: echo 'date > /tmp/foo' | at now + 1 minute However, you can simplify the quoting if you use heredocs: at -m $hour:$minute <<EOF /home/user/sipcmd -P sip -u 10shi -c swordfish -w 127.0.0.1 -f "msyb.wav" -x "c$extension;vmsyb.wav;ws1; EOF Those quotes will go as-is to the ...


2

What you're doing is tricky. The normal way is to avoid this and just pass the array values as arguments. In order to have both options, you would have to use eval: #!/bin/bash function populate_array () { if [ "$#" -gt 0 ] ; then # Enter array w/ elements as argument of executable # Note the quotes, they are needed ...


0

Special characters typically have to be escaped with backslash, like so: $ array-script.sh lkl1239 343.4l 3,344 \(34\) "lklk lkl" lkaa\ lkc 6 array elements lkaa lkc lklk lkl (34) 3,344 343.4l lkl1239 The brackets are treated by the shell as metacharacters, hence need to be ...


0

Just quote the $@ as you already correctly do in the function invocation: array=("$@") As man bash puts it: "$@" is equivalent to "$1" "$2" ...


0

I think this is what you're asking: You need to run screen -dmS (somenamegoeshere) -X (pathtoscript) and replace (somenamegoeshere) with a unique name to identify it and (pathtoscript) with the path to your script.


0

Quoting the docs on the behaviour of an interactive shell: The -n invocation option is ignored, and ‘set -n’ has no effect (see The Set Builtin). Since you sourced the script from an interactive shell, set -n is ignored.



Top 50 recent answers are included