bash

mod_fcgid - strange log line wraping

In my shell script that I run as a cgi application using fast cgi, when I echo as below, the log lines in apache error log appears broken up ( as shown below ). Anu idea why this happens? echo "a few words - some other words" 1>&2 In the log file [Tue Apr 27 12:27:54 2010] [warn] mod_fcgid: stderr: a few words - [Tue Apr 27 12:27:54 ...

Cross-platform getopt for a shell script

I've just found out that getopt is not cross-platform (in particular for FreeBSD and Linux). What is the best workaround for this issue? ...

Exclude string from wildcard in bash

Hi, I'm trying to adapt a bash script from "Sams' Teach Yourself Linux in 24 Hours" which is a safe delete command called rmv. The files are removed by calling rmv -d file1 file2 etc. In the original script a max of 4 files can by removed using the variables $1 $2 $3 $4. I want to extend this to an unlimited number of files by using a wi...

Bash or Bourne Scripts?

Is it better practice to write Bash scripts or Bourne scripts? My team writes Bourne scripts but I am not entirely sure why. If this is a holy war question (ie: vim vs. emacs) please just reply: holy war. ...

Bourne Script: Redirect success messages but NOT error messages

This command: keytool -import -file "$serverPath/$serverCer" -alias "$clientTrustedCerAlias" -keystore "$clientPath/$clientKeystore" -storepass "$serverPassword" -noprompt Will when it runs successfully outputs: Certificate was added to keystore I tried redirecting the stdard out with: keytool ... > /dev/null But it is still prin...

Bourne Shell: Convert ~/Desktop to /users/me/Desktop

The keytool does not resolve impartial directories. Ie this works: keytool -keystore "/users/me/Desktop" ... This doesn't: keytool -keystore "~/Desktop" ... Is there something that I could call like this: keytool -keystore "$(<cmd> ~/Desktop)" ... Update I guess I should actually be more specific: This is really what I am doi...

Netstat -i redirection problem

Hi ..When I run this command netstat -t 1 -i 2>&1 > $NETStat_OUT_FILE & inside a script , the output of netstat does not get redirected to the file.. Could any one find a solution for this ? ...

Copy/publish images linked from the html files to another server and update the HTML files referencing them

I am publishing content from a Drupal CMS to static HTML pages on another domain, hosted on a second server. Building the HTML files was simple (using PHP/MySQL to write the files). I have a list of images referenced in my HTML, all of which exist below the /userfiles/ directory. cat *.html | grep -oE [^\'\"]+userfiles[\/.*]*/[^\'\"] |...

bash bcmath functions

I have two functions for GNU bc in a Bash script. BC_CEIL="define ceil(x) { if (x>0) { if (x%1>0) return x+(1-(x%1)) else return x } else return -1*floor(-1*x) }\n" BC_FLOOR="define floor(x) { if (x>0) return x-(x%1) else return -1*ceil(-1*x) }\n" echo -e "scale=2"$BC_CEIL$BC_FLOOR"ceil(2.5)" | bc Both functions work fine in interacti...

How to load different zshrc file via commandline option?

I used to do this with bash... /bin/bash --rcfile /home/sindhu/bin/misc_scripts/shellrc/.bashrc_1 how can I accomplish the same with zsh? Thank you.z ...

finding the missing values in a range using any scripting language - perl, python or shell script

I got stuck in one problem of finding the missing values in a range and the range is also variable for the successive rows. input 673 673 673 676 676 680 2667 2667 2668 2670 2671 2674 output should be like this 674 675 677 678 679 2669 2672 2673 This is just one part and the row values can be more also If you need any clarification,...

Wrapper around bash, control STDIN and STDOUT

I would like to talk to a interactive bash process. Here is an example, so you know what I want to archieve: Program starts a new bash process. User types "ls" into my program. Program sends this command to the bash process. Program reads all available output of the bash (including the prompt) and displays it back to the user. GOTO 1 ...

Bash: How to invoke command and store the result in a variable?

Basically I want to be able to invoke a given command, in this case mysql -uanon -ppwd -db mydb -e "select count(*) from table1". And then take this commands result (the count on that table) and place it in a variable in bash script. What is the simplest way to achieve this? ...

spawn an entirely separate proccess in linux via bash

I need to have a script execute (bash or perl or php, any will do) another command and then exit, while the other command still runs and exits on its own. I could schedule via at command, but was curious if there was a easier way. ...

echo that shell-escapes arguments

Is there a command that not just echos it's argument but also escapes them if needed (e.g. if a argument contains white space or a special character)? I'd need it in some shell magic where instead of executing a command in one script I echo the command. This output gets piped to a python script that finally executes the commands in a mo...

intelligent thin start with port alias for bash

i would like a single alias (ts) which starts my local development server. the script should test for an open port starting at 3000 and use the first available port. additionally, some sites require a rackup file, making -R config.ru necessary. this script should check the current directory for the config.ru file and add that to the alia...

can i do multiple things in one command on linux?

I'm testing something where I'm compiling some code and analysing output with a Perl script. So first I run make, manually copy & paste the output to errors.txt and then running my Perl script (running: perl analysis.pl) in terminal. Is there away I can do this just with one line in bash? ...

bash completion for Subversion

I've tried to load bash_completion in my bash (3.2.25), it does not work. No message etc. I've used the following in my .bashrc if [ -f ~/.bash_completion ]; then . ~/.bash_completion fi I also tried to use .bash_profile instead, but with the same result. So the problem is why does it not work? Any idea? Hints? ...

Recursive follow files in bash

I have files which contain file names pointing to other files. These files contain further file names pointing further files and so on. I need a bash script which follows each files recursively and logs into file every touched file during the run. file1: file2 file3 file2: file4 file3: file5 file4 and file5 are empty. Re...

In Bash, how do you access command line arguments inside a function?

I'm attempting to write a function in bash that will access the scripts command line arguments, but they are replaced with the positional arguments to the function. Is there any way for the function to access the command line arguments if they aren't passed in explicitly? # Demo function function stuff { echo $0 $* } # Echo's the nam...