Tag Info

Hot answers tagged

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


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


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


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


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


4

To match repeating extensions, with zsh: rm -- *.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'}) Recursively: rm -- **/*.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'}) That would match a.php.php and b.x.x and c.x.y.x.y (and .php.php). With ksh93: rm -- *@(.*)\1 Recursively: set -o globstar rm -- **/*@(.*)\1 With GNU find, recursively: find . -regex ...


4

rm -- *.php.php this will delete all files that have more than one php extension for all sub directories you need find /scripts/tmp -name "*.php.php" -exec rm {} + /scripts/tmp is the directory under which my files and subdirectories existed


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

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


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


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


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


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


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


2

The main difference between runnning /etc/init.d/foo start and service foo start, is that service runs the init script in a clean environment. If you have a case where running the init script directly works, but does not with service, the an environment variable is being used in the startup that you have not manually initialized inside of the script. Since ...


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


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


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


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


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


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


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


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

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


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



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