bash

Rename files in bash keeping the originals untouched

I have a folder with a lot of images for a multilingual site, the images are stored in the next format filename.lang_code.jpg, on the deploy script i want to pick the correct one for the site I'm deploying and copy it to filename.jpg so I can share the same css between the sites. So, what I need is something like the command rename, but...

Appending to line with sed, adding separator if necessary

Hi I have a properties file, which, when unmodified has the following line: worker.list= I would like to use sed to append to that line a value so that after sed has run, the line in the file reads: worker.list=test But, when I run the script a second time, I want sed to pick up that a value has already been added, and thus adds a...

Using output of previous commands in bash

In Mathematica, it is possible to reuse the output of the previous command by using %. Is something similar possible for bash (or some other shell)? For example, I run a make which gives warnings, but I want to find all warnings. So, I type make | grep "warning" but I'm not able to see the output of the make then. I would like to ...

Filesystem walking iterator from the terminal

Is there a simple bash executable program (SIMPLE!!! in the repositories!) to iterate the file tree in a specified order (infix, prefix, postfix whatever) while executing a function on the files? Specifically i want to make a large list of the names of files on the root of one or more dirs. I could do this on java easy (in fact i alread...

How can a shell script control another script

I remember vaguely a technique using pipes for communication between two shell processes. Are there any tutorials available on how to setup and control a subshell? ...

Git for Web Developing

I'm attempting to create a set of git repositories and web folders in a server using the post-update hook. It would be something like: //server/dev (for dev files) and //server/web (the apache main path) The post-update hook for the //server/dev git repositories: #!/bin/sh unset GIT_DIR PROJECT=`basename $(pwd)` cd ../../web/${PROJEC...

check if a line is empty using bash

Hello, I am trying to do a simple comparison to check if a line is empty using bash: line=$(cat test.txt | grep mum ) if [ "$line" -eq "" ] then echo "mum is not there" fi But it is not working, it says: [: too many arguments Thanks a lot for your help! ...

Is there a better way to double escape (or escape twice) user input in BASH than calling printf twice?

This script will read an old and a new value from the user and then use sed to find and replace them in a file. For example if I entered T*T*z and B*B*z it would look for T\*T\*z in the file and replace with B\*B\*z. It works but I've been trying to make this more concise. I don't have any need for the intermediate variables $ESC_OL...

Running R Scripts with Plots

Hello all, I have a small shell script (bash) which runs a R script which produces a plot as output. Everything works fine but immedietly after the plot is rendered R quits. Is there a way to keep the R session alive until the plot window is closed. The shell script. #!/bin/bash R --slave --vanilla < myscript.r And the R script. da...

How to wait for a task to complete before continuing shell script

I have two shell scripts to write that will be executed nightly via cron schedule. On my production server: mysqldump -ufoo -pbar --opt --routines db > ~/sqldump/{$todays_date}.sql ln -s ~/sqldump/{$todays_date}.sql latest.sql On my development server: scp [email protected]:~/sqldump/latest.sql ~/sqldump mysql -ufoo -pbar db < latest...

How to Sort Output from several Log Files by date

Hi, I have got output from several different log files: logfile3 2010/07/21 15:28:52 INFO xxx 2010/07/21 15:31:25 INFO xxx 2010/07/21 15:31:25 DEBUG xxx logfile1 2010/07/21 19:28:52 INFO xxx 2010/07/21 19:31:25 INFO xxx 2010/07/21 19:31:25 DEBUG xxx logfile2 2010/07/21 13:28:52 INFO xxx 2010/07/21 13:31:25 INFO xxx 2010/07/21 13:31:2...

how to use a shell script to supervise a program?

I've searched around but haven't quite found what I'm looking for. In a nutshell I have created a bash script to run in a infinite while loop, sleeping and checking if a process is running. The only problem is even if the process is running, it says it is not and opens another instance. I know I should check by process name and not pr...

Stack multiple libnotify popups

Does anybody know how i can get multiple popups sent via notify-send to appear on screen at once. With: $ notify-send 'Message One' 'Body One' & notify-send 'Message Two' 'Body Two' & notify-send 'Message Three' 'Body Three' Each one waits for the previous popup in the queue to expire before being shown, i'm trying to get all three t...

Creating files in a *nix environment with an email address as its name

PLEASE don't tell me why you think its a bad idea. Just tell me if its a workable idea. I want to create files in a folder with names like the following: [email protected] [email protected] [email protected] Is there some fundamental incompatibility in the characters allowed in email addresses and those allowed by a unix syst...

Bash Script sed -e

count_items=`curl -u username:password -L "websitelink" | sed -e 's/<\/title>/<\/title>\n/g' | sed -n -e 's/.*<title>\(.*\)<\/title>.*/\1/p' | wc -l` Above I have a Bash script that extracts the titles from an XML file, but how do I change the regex so that it extracts a title name from a div tag? Example: extract title out of: <div i...

how to get line cut after a sign

I have a lines: something ..fdfad ABCD info fdsafsda fae faefdsa fABCD info23 I want get line after ABCD ...

Bash script for /dev semi-mounted volume

I am trying to write a bash script to automatically mount a volume that is in /dev (EC2 EBS storage). When the device is connected, it shows up as /dev/sdf (always)...but the "find" command does not work on it when it is there (just not technically mounted in /etc/mtab). These do not work: [ -f /dev/sdf ] && echo "It exists" || echo ...

taint-mode perl: preserve suid when running external program via system()

I'm trying to add a feature to a legacy script. The script is suid, and uses perl -T (taint mode: man perlsec), for extra security. The feature I need to add is implemented in Python. My problem is that I can't convince perlsec to preserve the suid permissions, no matter how much I launder the environment and my command lines. This is...

Passing variables in remote ssh command

I want to be able to run a command from my machine using ssh and pass through the environment variable $BUILD_NUMBER Here's what I'm trying: ssh [email protected] '~/tools/run_pvt.pl $BUILD_NUMBER' $BUILD_NUMBER is set on the machine making the ssh call and since the variable doesn't exist on the remote host, it doesn't get picked up....

How can I send html mail using a shell script?

As the question title says, how can I send html mail using a shell script? ...