bash

Shell Script That Can Check if it Was Backgrounded at Invocation

Hi All, I have written a script that relies on other server responses (uses wget to pull data), and I want it to always be run in the background unquestionably. I know one solution is to just write a wrapper script that will call my script with an '&' appended, but I want to avoid that clutter. Is there a way for a bash (or zsh) script...

Help debugging a cron job which has the correct script path and works when manually triggered

Hi, I'm struggling trying to debug a cron job which isn't working correctly. The cron job calls a shell script which should unrar a rar file - this works correctly when i run the script manually, but for some reason it's not working via cron. I am using the absolute file path and have verified that the path is correct. Has anyone got an...

Bash: using a the result of a diff in a if statement

Hello, I am writing a simple Bash script to detect when a folder has been modified. It is something very close to: ls -lR $dir > a ls -lR $dir > b DIFF=$(diff a b) if [ $DIFF -ne 0 ] then echo "The directory was modified" Unfortunately, the if statement prints an error: [: -ne: unary operator expected I am not sure what is w...

Bash scripting: Deleting the oldest directory

Hello, I have a simple Bash question which I do not seem to be able to get right. I want to look for the oldest directory (inside a directory), and delete it. I am using the following: rm -R $(ls -1t | tail -1) ls -1t | tail -1 does indeed gives me the oldest directory, the The problem is that it is not deleting the directory, and t...

Bash script for outputting list of specific log files to a text file

Hi All, I am trying to create a text file that contains a listing of all log files that contain a certain string in the first line. More specifically, SAS log files. Currently I have a simple script that will search the entire system for "*.log" files and output the entire list to a text file. Is there a way to only output the log ...

Bash script to recursively step through folders and delete files

Can anyone give me a bash script or one line command i can run on linux to recursively go through each folder from a root folder and delete all files or directories starting with '._'? Thanks, Dane. ...

How to escape an @ sign in the password field of an smb:// URL

Hi, I'm trying to write a bash script in which I connect to a samba server, by getting the username and password, then saying $username:$password@SERVERNAME. However, this will fail if the password has an @ in it. Is there a way to escape the @ out of the password in bash? Thanks in advance Update: I'm setting up this network printer...

Using sed to combine multiple csv files

I have 3 csv files I'd like to combine. Each file has 3 comma delimited columns. File 1 has columns a,b,c File 2 has columns d,e,f File 3 has columns g,h,i I'd like to combine the 3 files into a single file of: a,b,c,e,f,h Can I use sed to do that? I could write a console app or script easily enough but I'm attempting to get some...

Convert special characters in bash shell script

How do I write a bash shell script (under Mac OS X) to convert the names of various files with special characters such as ä, ö, ü? Using sed doesn't work: echo * | sed s/ü/ue/ Can I do it some other way? EDIT Here is the full script. It basically zips up iPhone app packages and then (should) convert any special characters in the zip...

git post-commit hook - script on commited files

Hello, Can I see somewhere an example post-commit hook to run a script on each commited file? eg. git add file1 git add file2 git commit -am "my commit" and the hook executes: myscript -myparams "file1" myscript -myparams "file2" The best would be to have parameter to commit command to run this hook or not, eg. git commit -X… e...

Tab autocompletion in bash using php

Hey guys, I'm writing a simple script to autocomplete when I press TAB. The php script contains a simple "echo". In this case, the autocomplete works but a "tab" is appended to the output making it useless Code from the script scriptPath='/home/hassen/workspace/scripts/bin/test.php' _dda() { local cur COMPREPLY=() u...

How to find PID of an dash-exec command

NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which has this weird exec problem. I have a simple bash shell script on Linux which is used to launch a server process (which I did not write or control) and would like to have the bash shell script output the launched process's PID to a pidfile. The problem is that ...

Bash: piped argument to open command fails. Open commands excutes too early?

I'm pretty much a novice to shell scripting. I'm trying to send the output of some piped commands to an open command in bash in OSX. My ultimate goal is to compile a Flex/Actionscript application from TextWrangler by calling a bash script with a little Applescript and have the result played directly in a Flash Player. The Applescript is...

pipe only stderr through a filter

Is there any way, in bash, to pipe stderr through a filter before unifying it with stdout? That is, I want stdout ----------------\ |-----> terminal/file/whatever stderr -- [ filter ] --/ rather than stdout ----\ |----[ filter ]---> terminal/file/whatever stderr ----/ ...

creating alias in bash

Currently this is what I need to type to execute my task execute 'mytask' I want an alias so that I need to type e mytask This is what I did which is not working alias e="execute '$1'" ...

modify shell script to delete folders as well as files

My shell script: #!/bin/bash if [ $# -lt 2 ] then echo "$0 : Not enough argument supplied. 2 Arguments needed." echo "Argument 1: -d for debug (lists files it will remove) or -e for execution." echo "Followed by some path to remove files from. (path of where to look) " exit 1 fi if test $1 == '-d' then find $2 -mmi...

Running all NUnit tests in all assemblys from Cygwin command line

Hey all, I'm trying to create a short bash script someone could run in cygwin to execute all nunit tests in a .NET project using nunit-console. Currently i have the system version of nunit aliased to "nunit" so if i run "nunit" it will execute nunit-console. My first step was to try and find all the test assemblies recursively. This ...

How do I make the "1.9.2" Ruby string point to the final release with RVM?

I'm using RVM to manage my Ruby environment on OSX, and currently it's interpreting '1.9.2' as ruby-1.9.2-rc2 instead of the final release. How can I update this to make it behave as expected? ...

zsh vi mode status line

Is there a way in zsh or bash to have a status line? e.g. in VI it will let you know that you are in insert mode with -- INSERT -- Is there an eqivalent for the command line? ...

Bash script - How to take todays date and count back monthly for a year

Hi, I've made a bash script executing a PHP file: #!/bin/bash php upgrade_attendance.php refresh_daily_attendance 2010-10-01 2010-11-01 php upgrade_attendance.php refresh_daily_attendance 2010-09-01 2010-10-01 php upgrade_attendance.php refresh_daily_attendance 2010-08-01 2010-09-01 php upgrade_attendance.php refresh_daily_attendance ...