Tag Info

Hot answers tagged

13

Showing date & time in the active window's title Running the script below (an edited version of this one) in the background, the front most window will show the current date & time: If the window loses focus, the time will not be updated; only on the front most window, the time will be updated. The script also shows the date & time per tab on ...


13

What are my options? Is there another path with the same "run from anywhere" capability, which I can access without sudo, or another way to achieve something equivalent? How to do it? Create some dir in your home to hold your scripts normally named as bin as convention. mkdir ~/bin Now move your scripts to bin mv somescript ~/bin Now how to ...


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


9

Using awk awk '{for (i=1;i<=NF;i++) sum[i]+=$i;}; END{for (i in sum) print "for column "i" is " sum[i];}' FileA for column 1 is 8 for column 2 is 11 for column 3 is 7 for column 4 is 5


6

If you want to check that all of them are installed, just do: hash foo bar baz &>/dev/null && echo "All programs installed" || echo "At least one program is missing" The &> redirects standard error and standard output to /dev/null so you don't print the output of hash. You probably only need 2> since as far as I know, ...


6

It's a simple shell script: Requirements xdotool sudo apt-get install xdotool wmctrl sudo apt-get install wmctrl Main part wmctrl -r :ACTIVE: -N "$(awk -F' \\|\\|' '{print $1}' <<< $(xdotool getwindowfocus getwindowname)) || $(date "+%Y-%m-%d %H:%M:%S")" The || is the separator between the window title an the date/time part. If you ...


5

To position a window, you can use a tool that manipulates X events such as xdotool or wmctrl. For example, with wmctrl, you can use -e: -e <MVARG> Resize and move a window that has been specified with a -r action according to the <MVARG> argument. <MVARG> A move and resize argument has the format ...


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 ...


5

Create some scripts sudo nano /usr/local/bin/rsync_html #!/bin/bash /usr/bin/rsync -av --delete /var/www/html /media/stan/Seagate\ Expansion\ Drive/backups/ sudo nano /usr/local/bin/rsync_documents #!/bin/bash /usr/bin/rsync -av --delete /home/stan/documents /media/stan/Seagate\ Expansion\ Drive/backups/ sudo nano /usr/local/bin/rsync_backups ...


4

In addition to http://askubuntu.com/a/643030/218015 you might can also define an alias inside your .bashrc for small, often used tasks. E.g. alias ll='ls -l' alias ls='ls --color=auto' will create you a "command" ll, which is doing ls -l and ls will be coloured after defining the alias. https://wiki.ubuntuusers.de/alias is having some more examples and a ...


4

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 ...


4

Here's a script that utilizes bash, xprop, and wmctrl (does not come with ubuntu). This script can be added as an autostart entry or placed into .desktop file. Basic idea is to get current active window's id, store its current title, and use output of date command and title to form a new title. The if statement prevents infinite loop of appending date. You ...


4

First of all, you don't want to do gradle="...". That simply creates a variable called gradle and is irrelevant (unless that variable is somehow used by gradle but you haven't said so). What you want to do is add the directory containing the gradle executable to the list of directories your system searches through when trying to find programs to run. This is ...


3

Judging by the comments to your own answer, you only want the sum of one column at a time. If so, here is a non-awk way to do it: cut -d' ' -f3 FileA | grep . | paste -s -d+ | bc where you would replace the 3 with the column number you are interested in.


3

I'm not sure why you'd want to do this, but you can handle this slightly more elegantly than a raw copy. mkdir -p $HOME/wow/meow cp "$(readlink -f $0)" "$HOME/wow/meow" It's using $HOME so we aren't reliant on a hard-coded path (moderately more reliable than the ~ substitution for scripting). We check that the target directory exists (and create it if ...


3

So basically you run a script that makes everything inaccessible, and you want quick and easy solution to stop it . An alternative to powercycling is to hold SYSRQ key (it's same as PRTSC key in many cases), and press one by one R, E, I,S,U,B. Basically that's a safe way to kill all running processes and restart the system. Alternative to that is to do ...


3

With your requirements you need something like this oneliner with an output file: (echo -e "SCF DONE\n1.0\n15.0 0 0\n0 15.0 0\n0 0 15.0\nTi O\n1 2\nDirect"; awk '/Ti|O/ {print $2 " " $3 " " $4}' foobar) > output_file and without: echo -e "SCF DONE\n1.0\n15.0 0 0\n0 15.0 0\n0 0 15.0\nTi O\n1 2\nDirect"; awk '/Ti|O/ {print $2 " " $3 " " $4}' foobar Or ...


3

Try this: for f in *; do if [[ -d $f ]] ; then mv "$f" $(($f + 1000)) fi done


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.


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 ...


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 | ...


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


2

Add a line in the script to copy itself: cp /home/user/Documents/sh/test.sh home/user/wow/meow/


2

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 ...


2

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. ...


2

You could use this: var=( $(< input awk '/VARIABLES {/, /}/ {if ($0~/VARIABLES/||$0~/}/) next; else gsub(/[ ,]/, "", $0); print}') ) prints every record between a record matching VARIABLES { and a record matching }, removing every and , character However I'd rather use mapfile and a single fork in place of a double fork to store values into an ...


2

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: ...


2

Using awk to create an SQL query: find . -type f -maxdepth 1 -exec awk -F_ '{print "INSERT INTO table (service_id, mac_adress) VALUES (\""$1"\",\""$2"\");"}' {} \; Example output: INSERT INTO table (service_id, mac_adress) VALUES ("TBBN027162G", "38d8-2f08-0c40"); INSERT INTO table (service_id, mac_adress) VALUES ("TBBN027605G", "38d8-2f08-1518"); INSERT ...


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 ...


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)



Only top voted, non community-wiki answers of a minimum length are eligible