bash

bash script parameters

I need to write a bash script, and would like it to parse unordered parameters of the format: scriptname --param1 <string> --param2 <string> --param3 <date> Is there a simple way to accomplish this, or am I pretty much stuck with $1, $2, $3? ...

How can I use bash (grep/sed/etc) to grab a section of a logfile between 2 timestamps?

I have a set of mail logs: mail.log mail.log.0 mail.log.1.gz mail.log.2.gz each of these files contain chronologically sorted lines that begin with timestamps like: May 3 13:21:12 ... How can I easily grab every log entry after a certain date/time and before another date/time using bash (and related command line tools) without compar...

String interpolation in Bash

My code #!/bin/bash for (( c=0; c<=1127; c++ )) do id = 9694 + c if (id < 10000); then wget http://myurl.de/source/image/08_05_27_0${id}.jpg else wget http://myurl.de/source/image/08_05_27_${id}.jpg fi done I only get ./get.sh: line 5: 10000: No such file or directory --2009-05-06 11:20:36-- http://myurl.de/source/image/08_05_27...

Minimal "Task Queue" with stock Linux tools to leverage Multicore CPU

What is the best/easiest way to build a minimal task queue system for Linux using bash and common tools? I have a file with 9'000 lines, each line has a bash command line, the commands are completely independent. command 1 > Logs/1.log command 2 > Logs/2.log command 3 > Logs/3.log ... My box has more than one core and I want to execu...

"Bad Interpreter: No Medium" error when running Ruby from Git Bash

I'm seeing this error when I run: rake/gem from my Git Bash. Anyone know what it means? sh.exe": /c/Ruby/bin/gem: D:/Users/Luis/projects/oss/oci/installer2-trunk/ruby/bin/ruby.exe^M: bad interpreter: no medium Running under Windows/Cygwin - specifically in the Git Bash shell. ...

Executing commands containing space in bash

I have a file named cmd that contains a list of unix commands as follows: hostname pwd ls /tmp cat /etc/hostname ls -la ps -ef | grep java cat cmd I have another script that executes the commands in cmd as: IFS=$'\n' clear for cmds in `cat cmd` do if [ $cmds ] ; then $cmds; echo "****************************"; ...

How to use environment variable inside a quoted string in BASH script

I've tried various forms of the following in a bash script: #!/bin/bash svn diff $@ --diff-cmd /usr/bin/diff -x "-y -w -p -W $COLUMNS" But I can't get the syntax to correctly expand the COLUMNS environment variable. I've tried various forms of the following: svn diff $@ --diff-cmd /usr/bin/diff -x '-y -w -p -W $COLUMNS' and svn d...

Like to store all command-line arguments to a bash script into a single variable

Let's say I have a bash script called foo.sh. I'd like to call it like this foo.sh Here is a bunch of stuff on the command-line and I'd like it to store all of that text into a single variable and print it out. So my output would be: Here is a bunch of stuff on the command-line How would I do this? ...

Can I put something in in bashrc to hide text editor (~ extension) files?

I'd like to do ls without seeing all the ~ files generated by vim. Is it possible? ...

Bash in vi-mode: browsing shell history with cursor up/down, cursor position not at the end?

I'm very fond of vim and really would like to enhance my bash experience with vi-mode. However one thing I'm so accustomed to the emacs behavior in that, when browsing the shell history with cursor up/down, the cursor is positioned at the end of the line. In vi-mode it's the other way around; the cursor is always positioned at the begin...

How do I find my computer's IP address using the bash shell?

Every now and again, I need to start the Django development server, and have it viewable by other machines on my network, as described here: http://docs.djangoproject.com/en/dev/ref/django-admin/#runserver My machine’s IP address tends to change every now and again, so I’d like to have a little shell alias or something that spits out t...

How to use > in an xargs command?

I want to find a bash command that will let me grep every file in a directory and write the output of that grep to a separate file. My guess would have been to do something like this ls -1 | xargs -I{} "grep ABC '{}' > '{}'.out" but, as far as I know, xargs doesn't like the double-quotes. If I remove the double-quotes, however, then...

Tricky brace expansion in shell

When using a POSIX shell, the following touch {quick,man,strong}ly expands to touch quickly manly strongly Which will touch the files quickly, manly, and strongly, but is it possible to dynamically create the expansion? For example, the following illustrates what I want to do, but does not work because of the order of expansion: T...

script-file vs command-line: problem with rsync and --exclude

Hi all I have a simple test bash script which looks like that: #!/bin/bash cmd="rsync -rv --exclude '*~' ./dir ./new" $cmd # execute command When I run the script it will copy also the files ending with a ~ even though I meant to exclude them. When I run the very same rsync command directly from the command line, it works! Does some...

Bash: check user input is correct

Hi there Im wrote a bash script that takes numbers for calculation via user input, the problem i have is if the user types a letter or a space by mistake the whole script fails and the user must start again. There must be an easy way to check the input is numeric only that will ask for the input again if anything else is input accident...

How can I append text to /etc/apt/sources.list from the command line?

I am new to linux, and just beginning to learn bash. I am using Ubuntu 9.04, and would like to add repositories to /etc/apt/sources.list from the command line. Basically, I would like to do this: sudo echo "[some repository]" >> /etc/apt/sources.list However, even when I use sudo, I get this error: bash: /etc/apt/sources.list: Permis...

How can I remove missing files with spaces in svn?

I have this snippet i found. svn status | grep '\!' | awk '{print $2;}' | xargs svn rm It removes all missing files, if I or someone deletes the files manually (via the editor or they are deleted via the system) But my bash coding is not great, what it's missing is that it does not work with files that have spaces in it. svn rm Supe...

Can the find command's "exec" feature start a program in the background?

I would like to do something like: find . -iname "*Advanced*Linux*Program*" -exec kpdf {} & \; Possible? Some other comparable method available? ...

Getting sed to Replace Text With Argument

Alright, I know this is a simple question, but I can't seem to get this sed command to work. I'm trying to get a text file and replace one bit of it from placeholder text to a study code. The study code that it is going to replace it with is passed into the script using arguments when the script is first ran. The problem is, when I tr...

How Do I Backup My PostgreSQL Database with Cron?

I can run commands like vacuumdb, pg_dump, and psql just fine in a script if I preface them like so: /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/prevac.gz /usr/bin/sudo -u postgres /usr/bin/vacuumdb --analyze mydatabase /usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase > /opt/postgresql/postvac.gz...