bash

Piping SQL to mysql via -find -exec

I cannot for the life of me get this. Example of fails, the last line of which adds in sed, which is the ultimate goal: find -maxdepth 1 -name "*.sql" -exec "mysql -D ootp < {}" \; find -maxdepth 1 -name "*.sql" -exec "mysql -D ootp << {}" \; find . -maxdepth 1 -name \"*.sql\" -exec /usr/bin/mysql -D ootp << sed -e 's/ , );/1,1);/g' {} ...

Quoting not respected inside a bash variable

I'm storing the arguments to a command in a variable. The final command I want is: mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm Here's my attempt: set -x # for debugging RESULTDIR=results MOCK_CONFIG="myconfig" MOCK_ARGS="-r $MOCK_CONFIG --define \"debug_package %{nil}\" --resul...

In a bash script, how can I exit the entire script if a certain condition occurs?

I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests. Is there a way I can do this without wrapping the entire script inside of a while loop and using breaks? Something like a dun dun dun goto? ...

Bash Script - umount a device, but don't fail if it's not mounted?

I'm writing a bash script and I have errexit set, so that the script will die if any command doesn't return a 0 exit code, i.e. if any command doesn't complete successfully. This is to make sure that my bash script is robust. I have to mount some filesystems, copy some files over, the umount it. I'm putting a umount /mnt/temp at the sta...

Activating KDE 4 notifications from bash scripts

I have a bash script activated by crontab and running in background. I would like to add to it the ability to send notifications during the execution. My KDE 4 desktop has a fancy notification system which pops out non-modal messages from the tray bar, and this would be perfect for my needs. So I was searching for a way to generate these...

Replace important symbolic link ‘safely’

I would like to change the target of symbolic link from within a bash script. The problem is that the symlink is quite important (it's /bin/sh, namely) and I would to do it in fashion that: New target will be available immediately after removing old, i.e. there will be no possibility that something will notice disappearing of it, There...

Is there a bash shortcut for traversing similar directory structures?

The Korn shell used to have a very useful option to cd for traversing similar directory structures e.g. given the following directorys /home/sweet/dev/projects/trunk/projecta/app/models /home/andy/dev/projects/trunk/projecta/app/models Then if you were in the /home/sweet.... directory then you could change to the equivalent director...

Hide a bash function internals..

Hi, My .bashrc looks something like this... export PERL5LIB="/tools/perl/Linux/${PLAT}/lib/perl5/5.10.0/${PLAT}-thread-multi" export PERL5LIB="${PERL5LIB}:/tools/perl/Linux/${PLAT}/lib/perl5/5.10.0" function dev { export PERL5LIB="/dev/tools/perl/Linux/${PLAT}/lib/perl5/5.10.0/${PLAT}-thread-multi" export PERL5LIB="${PERL5LIB...

Bash quoting of current path (pwd)

Dear lazyweb, I have encountered a most annoying problem that occurs on the PWD variable when the current path includes a space. My code looks somewhat like this: mycommand |sed -E ' s|mystuff|replacement| ; s|'$(pwd)'|replacement| ; ' This works great, unless the current path contains a space character. If it does, $(pwd) i...

How do I reverse escape backslash ecodings like "\ " and "\303\266" in bash?

I have a script that records files with UTF8 encoded names. However the script's encoding / environment wasn't set up right, and it just recoded the raw bytes. I now have lots of lines in the file like this: .../My\ Folders/My\ r\303\266m/... So there are spaces in the filenames with \ and UTF8 encoded stuff like \303\266 (which is ö...

running process in backround using a bash script

I want run a script as follows: runner: ssh 'java program &' ssh 'java program &' How do I write the script to fork the first process? Currently, it waits for it to finish. thanks ...

using gawk in a shell script

Hi I want to use gawk in a for loop. Something like this: for i in gawk {print $1} | tr '\n' ' ' do something using $i this isn't working of course. Ideas? ...

What information can be gathered about remote host on ssh login

I want to map users (that ssh to server) to emails. In csh you have defined $REMOTEHOST variable that contains PC name from remote host. In bash, no environment variable is defined. Is there any way to get some info about connected user (except from SSH_CLIENT which gives IP and PORT) Note that I'm using sshd and bash. ...

rename part of filename

Hello, sorry for the properly stupid question, but I am quite a newbie. I have loads of files which look like this: DET01-ABC-5_50-001.dat ... DET01-ABC-5_50-0025.dat and I want them to look like this: DET01-XYZ-5_50-001.dat ... DET01-XYZ-5_50-0025.dat how can I do this? I tried several things from this forum but I seem to make a...

commands from .bashrc not available in emacs

I have some aliases and functions defined in ~/.bashrc. I start emacs from a terminal window using emacs -nw When I execute M-x shell-command, the aliases and functions from ~/.bashrc are not available, but give a "command not found". I've googled quite a bit but all the posts I come across say, if I understand them correctly, that...

Bash: Detect if user's path has a specific directory in it

With /bin/bash, how would I detect if a user has a specific directory in their $PATH variable? For example if [ -p "$HOME/bin" ]; then echo "Your path is missing ~/bin, you might want to add it." else echo "Your path is correctly set" fi ...

What is the Perl equivalent to bash's "$@"?

I'm working on a Perl script that I was hoping to capture a string entered on the command line without having to enter the quotes (similiar to bash's "$@" ability). I'll be using this command quite a bit so I was hoping that this is possible. If I have: if ($ARGV) { I have to put the command line string in quotes. I'd rather do the...

How to run processes piped with bash on multiple cores?

I have a simple bash script that pipes output of one process to another. Namely:. dostuff | filterstuff It happens that on my Linux system (openSUSE if it matters, kernel 2.6.27) these both processes run on a single core. However, running different processes on different cores is a default policy that doesn't happen to trigger in th...

Shell script test

I'm tring to update a bash script written by someone else and I've come accross a line I'm not sure about. Can anyone tell me what the following check does: if [ :$RESULT != :0,0 ] I assume it's checking for some value in $RESULT, possibly with a substring? Any help appreciated! ...

How do I write a script to ssh to a computer from a remote computer?

I frequently need to ssh into a server, but I can't ssh into it directly while I'm connected to our VPN. Thus, I have to ssh into another server and ssh into it from there. Is there any way that I can write a script and/or shell function for this? I've tried this, buit it gave me an error: % ssh jason@server2 'ssh jason@server1' jaso...