Tag Info

New answers tagged

2

Use a gpg-agent and provide your password as: __password=$(gpg --decrypt /path/to/password.gpg) in your script. Of course, you need to previously encrypt it: $ echo "correct_horse_battery_staple" > password $ gpg --encrypt password


0

You must skip the first line: awk 'BEGIN { FS=":" printf "%-10s %-35s %-55s\n", "RANK", "PERFORMER","SONG" print "=====================================================================\n"} FNR==1{next}{printf "%-10s %-35s %-55s\n", $1, $3, $2}' songs If you don't mind the order of output, try: $ awk -F':' 'FNR==1{next}{a[$5]+=1} END{for(i in a){print ...


0

In order to print the input after the corresponding prompt, you need to know when the program is waiting for input. There's no way to tell from observing the running program: you can't distinguish a program that's waiting for input on stdin from a program that's waiting for something else (network, disk, computation, …). So the process to obtain a ...


0

Add the line set -x in your program file. Example: #!/bin/bash set -x #echo on ls $PWD This expands all variables and prints the full commands before output of the command. output: + ls /home/user/ file1.txt file2.txt Check this answer from Stackoverflow for more similar flags for the set command.


0

Well, if you always have the same number of fields per record and you don't have anything between records (assumptions I'm making based on your post which may or may not be correct), you could go the awk route. This will preserve column order and embedded newlines. Assume the following is in parse.awk: BEGIN { RS = "( = |\n\\s+)"; isHeader = ...


3

Most modern dekstops are EMWH compliant. You can use wmctrl to control those and the windows on them, e.g.: wmctrl -a <WIN> to activate a window by switching to its desktop and raising it (<WIN> can be various things, by default a string match on the window title, see the wmctrl man page).


0

I'm not exactly sure what you want to do because you don't show the actual input, just the output you want and various bits of code that are used in various stages. However, I think the following will do what you want (make sure you set -F: on the command line. If not, I've tried to describe each part to give you an idea of how to modify it. !/^#/ { ...


2

In your is_mounted function you should test the output of mount to confirm that something was returned and then return a 0 or 1 accordingly. Also I would highly encourage you to use the debugging facilities built into bash. You'll quickly see what's going wrong rather than have us try and debug it. Just put a set -x at the beginning of the block of code ...


0

The cleanest way to do this would be to have your comamnd1 return the PIDs of the launched processes and using wait on each of them as suggested by @LaurentC's answer. Another approach would be something like this: ## Create a log file logfile=$(mktemp) ## Run your command and have it print into the log file ## when it's finsihed. command1 && echo ...


7

You can use the command wait PID to wait for a process to end. You can also retrieve the PID of the last command with $! In your case, something like this: command1 & #run command1 in background PID=$! #catch the last PID, here from command1 command2 #run command2 while command1 is running in background wait PID #wait for command1, in background, to ...


1

I'll propose a different workflow (suggested by hasenj): instead of using fdupes to identify duplicate files and perform some post-processing to remove them, you can use Unison to identify and deal with duplicates. You need to run Unison with one of the roots remote, otherwise it doesn't detect identical files. So run unison /home/articles/bibtex.pdf ...


1

In practice, the kernel will cache the executable and any file it needs (e.g. libraries) in RAM. The shell has no way to do anything. If it's an external program, it needs to be executed. Unices (excluding unix emulation layers like Cygwin) tend to make loading a program pretty efficient, but it's never going to be as fast as executing a built-in command. ...


0

find . -name "*.xml" -print0 | xargs -0 touch Learn find | xargs


1

In my experience fdupes can be inconsistent in the order that it outputs files (I have had my own problems using the --delete option). This should be fairly robust as it doesn't require the files to be in a specific order (as as long as there are always two dupes in different folders): # note no trailing slash source_dir=/home/articles ...


0

No, it does not. What you can do is set the cron to run a script which contains your job and set it to run for a specific amount of time. Right before each time interval, terminate/kill that job from within that script and have cron restart it again at the moment of the next time interval.


6

No, the contract with cron is that it starts each job at the specified time. Cron doesn't keep track of which successive jobs are “the same job”. If you want to avoid starting a job when the previous one isn't finished, you need to put something at the beginning of your job that makes it exit early. For example, you can arrange for your job to hold a lock ...


0

You may want to focus on architectures, as well as specific languages: CGI web application frameworks the rise of open source software, such as the Apache HTTP server browser wars that led to the evolution of JavaScript as a mature programming language


3

The term "scripting language" is now-a-days really an ambiguous, wishy-washy, or just plain prejudicial one, but a discussion of how that came to be is a discussion of the evolution of the languages to which the label is often applied. Originally, scripting referred to languages whose source was interpreted at runtime instead of compiled (e.g., shells ...


1

just remove the & at then end of towhee towhee_input5 > output & In shell & means to put in background execution, if you want you process to run in foreground then just remove it and your script will go one once it ends. edit If you want to run the command in background and wait for it, then simply use wait towhee towhee_input5 > ...


1

find $DIR -depth -maxdepth 3 \ -type d -readable -printf \ 'printf "\\n%p\\n" ls -t --color=always "%p"\n' |\ . /dev/stdin 2>&- This avoids any argument list problems because the only argument ls will ever receive is the name of the directory you want listed. You can do this with anything you like. The shell just . sources the |pipe ...


1

To robustly list the filenames only using recent GNU tools: find . -printf '%A@ %p\0' | sort -nz | sed -z 's/^[^ ]* //' | tr '\0' '\n'


2

find -printf "%TY-%Tm-%Td %TT %p\n" | sort -n will give you something like 2014-03-31 04:10:54.8596422640 ./foo 2014-04-01 01:02:11.9635521720 ./bar


1

In bash, run shopt -s globstar first. In ksh93, run set -o globstar first. In zsh, you're already set. ls -dltr **/* This will return an error if you have so many files that the command line length limit on your system is exceeded. In zsh, you can use this instead: print -rl -- **/*(Om)


1

This one will list all files in <dir> with topmost being oldest modified find <dir> -type f -print0 | xargs -print0 ls -ltr And with this the latest modified is topmost find <dir> -type f -print0 | xargs -print ls -lt Note that this only works if the list of file names doesn't exceed the total command line length limit on your ...


7

This should work with all the image types that ImageMagick can handle without having to specify *.png, *.jpg, *.jpeg etc: #!/bin/bash images=$(identify -format '%f\n' * 2>/dev/null) IFS=$'\n' set -e max_dims=$( identify -format '%w %h\n' $images 2>/dev/null | awk '($1>w){w=$1} ($2>h){h=$2} END{print w"x"h}' ) orig_dir=originals_$(date ...


3

If you want to flatten the directory structure (thus sorting by date over all files in all directories, ignoring what directory the files are in) the find-approach suggested by @yeti is the way to go. If you want to preserve directory structure, you might try $ ls -ltR /path/to/directory which sorts directory based.


3

Assuming you are usuig GNU find, try: find $SOMEPATH -exec stat -c '%Y %n' '{}' + | sort -n


5

As long as you select a target size that is larger than your largest image, you should be fine with the following: mogrify -gravity Center -extent 200x200 -background white -colorspace RGB *png The command above will change the original file, you might want to backup before running it. It uses mogrify from ImageMagick to resize all pngs in the current ...


5

I took the opportunity to improve my bash skills and came up with this: #!/bin/bash maxx=0 maxy=0 # find largest dimension for file in *.jpg ; do dim=$(identify "$file" | awk '{ print $3 }') xdim=$(echo $dim | cut -f1 -dx) ydim=$(echo $dim | cut -f2 -dx) if [ $xdim -gt $maxx ] ; then maxx=$xdim fi if [ $ydim -gt $maxy ] ; then ...


0

Since my original Post was edited for grammatical issues.. I have to place this as a new "answer"... Here is another way to approach this and I did not think of it until this morning.. sed "/#/d" "/cygdrive/c/!chkout/ourlog" | gawk -F ":" "{print $1}" | sort | uniq -c | sort -r


3

Here is awk code to skip only the initial comments and then print $1 on the remaining lines: gawk -F: -v c=1 '/^[^#]/ {c=0} c==0 { print $1 }' ourlog Before the program starts, the variable c is set to 1. As soon as a non-comment line is found, c is set to zero and it stays that way for the rest of the execution. When c==0, the print statement is ...


2

Another option is to use pam - this will give you a precise way to define on-login actions. For a generic action you can rely on pam_exec (http://manpages.ubuntu.com/manpages/hardy/man8/pam_exec.8.html). However, if you need to perform a more specific action in a safe way, there may exist more specialized pam modules which will make a better fit, such as ...


7

There is no guarantee that the graphical display manager will read the classic startup files. This changes between distributions and between display managers. One of the following should work though. Use your desktop environment's native method to set startup applications. The details will depend on the DE you are using, but you can create a script that ...


2

According to this topic: Run command automatically after login? You have the solution of the .bashrc (not what you need) and the solution of startup applications. I quote Daniel S.: gnome-session-properties can be used to configure startup applications. Also, if you want an application to run at system boot, you can add a rule like the ...


3

i added the following to my crontab by typing crontab -e and it worked * * * * * env DISPLAY=:0 google-chrome www.github.com My chrome browser opened www.github.com every minute. So the following should work for you. * * * * * env DISPLAY=:0 chromium-browser http://mysite.com


2

A little late, but this will work recursively find . -name '*.JPG' -exec 'sh' '-c' 'mv {} $(sed "s/\.JPG$/\.jpg/" <<< {})' ';'


0

Sorry I too find it now thanks anyways rename 's/\.([^.]*$)/.\L$1/' *.JPG This will fix my issue


1

Easy way to repeat a job from crontab with an interval less than one minute (20 seconds example) : crontab: * * * * * script.sh script.sh: #!/bin/bash >>type your commands here. sleep 20 >>retype your commands here. sleep 20 >>retype your commands here.


2

You need to use the command, SHOW OPEN TABLES Experiment in my system I ran the command and this is the initial output that I got. "Database" "Table" "In_use" "Name_locked" db_name "table1" "0" "0" db_name "table2" "0" "0" Now, I ran a SELECT query on a table (table1) that had ...


3

Try the below script. It should work. declare -a array=('1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11') for ((i=0; i<=${#array[@]}; i+=2 )) ; do echo "Current Iterator i value:" $i echo "Array element at this position:" ${array[$i]} done Output of the script Current Iterator i value: 0 Array element at this position: 1 Current Iterator i ...


0

Systemd and init have pid = 1 pidof /sbin/init && echo "sysvinit" || echo "other" Check for systemd pidof systemd && echo "systemd" || echo "other"


0

If you know there are three columns, you could use paste: your_script.sh | paste - - -


0

#!/bin/bash { date +"%d:%m" >> dbdata.growth psql -h 192.168.2.173 -U postgres -c "select pg_database_size('ddb'); " | sed -n '3,3p' | numfmt --to=iec >>dbdata.growth psql -h 192.168.2.173 -U postgres -c "select pg_database_size('dpkidb'); " | sed -n '3,3p' | numfmt --to=iec >>dbdata.growth } | ( #all output from your commands ...


1

The solution would be to use subshells: #!/bin/bash var1=$(date +"%d:%m") var2=$(psql -h 192.168.2.173 -U postgres -c "select pg_database_size('ddb'); " | sed -n '3,3p' | numfmt --to=iec) var3=$(psql -h 192.168.2.173 -U postgres -c "select pg_database_size('dpkidb'); " | sed -n '3,3p' | numfmt --to=iec ) echo $var1 $var2 $var3 >>dbdata.growth


3

Replace all output lines, such as: date +"%d:%m" >> dbdata.growth with lines such as: date +"%d:%m" | tr -d $'\n' >> dbdata.growth This uses tr to delete newline characters before they are put in the output file. tr is a translate or delete utility. In this case, the use of the -d option tells it to delete. The character that we ask it ...


2

I agree w/ Ouki regarding keeping it simple and within the script for now. When and if you decide you want a man page, you can transplant to there and leave a simplified help. Examining 3 of 4 of your disadvantages to this approach vs. a separate file: The main script called with myscript command would be lighter There would be a trivial number ...


2

The 2 approaches I see here are more: setting a inline section or a POD-like documentation to display as help, or properly defining a .man file to add to your local man structure I honestly don't see the point of having a separate file for that kind of help, unless you have a very big tool and the interface/GUI is already in different file(s). So stay ...



Top 50 recent answers are included