bash

Shell Script that goes up N folders in the file system

Hey there, I just found this very usefull shell script here on SO but unfortunately it's not working on Mac OS X 10.5. This is the script in question(copied it for convenience): #!/bin/bash LIMIT=$1 P=$PWD for ((i=1; i <= LIMIT; i++)) do P=$P/.. done cd $P I tried to echo $P at the very end and it's returning the right path, but...

Script to recursively delete CVS directory on server

So far I've come up with this: find . -name 'CVS' -type d -exec rm -rf {} \; It's worked locally thus far, can anyone see any potential issues? I want this to basically recursively delete 'CVS' directories accidently uploaded on to a server. Also, how can I make it a script in which I can specify a directory to clean up? ...

Bash script to automatically create symlinks to subdirectories in a tree

Ok, this is my third try posting this, maybe I'm asking the wrong question!! It's been a few years since I've done any shell programming so I'm a bit rusty... I'm trying to create a simple shell script that finds all subdirectories under a certain named subdirectory in a tree and creates symbolic links to those directories (sounds more...

Is there an easy way to calculate quantiles with bash?

Lets say I have a log file from a web server with response times per request: _1st_request 1334 _2nd_request 345 _3rd_request 244 _4th_request 648 ......... etc Is there an easy way with bash scripting to find the top decile (10-quantile)? In other words to answer the question: How slow was the slowest request if I exclude the slowest...

Problem passing bash output to a python script

I'm fairly new to programming and I searched the internet for a way to pass bash output to a Python script. I came up with this in bash. XAS_SVN=`svn info` ssh hudson@test "python/runtests.py $XAS_SVN" And this in python. import sys print sys.argv[1] When I echo $SVN_INFO I get the result. Path: . URL: //svn/rnd-projects/te...

how to write a folder recursive script using bash

the problem is as the title. thx! ...

How can I use TFS for iPhone development?

I was struggling with how to use TFS as a source code repository for iPhone development. My boss will never let me use Subversion (or God forbid Perforce), so I was stuck with TFS source control. The solution is to go and buy tools to bridge Mac to TFS, and I am not trying to advertise here, but the Teamprise Client Suite for Mac OS X ...

How to slice an array in bash

(edited to fit the answer) Looking the "Array" section in the bash(1) man page, I didn't find a way to slice a bash array. So I came up with this overly complicated function: #!/bin/bash # @brief: slice a bash array # @arg1: output-name # @arg2: input-name # @args: seq args # ---------------------------------------------- function...

Why a hard coded string var is changing when the bash script is run as root ?

I am batch converting some pictures with a quick and dirty bash script using ufraw : IFS=$'\n' PICS="/media/disk/kevin/Images/"; for pic in $(find $PICS -name "*CR2"); do ufraw-batch $pic --out-type jpg --size=2048 --overwrite --out-path=$PICS; rm -f $pic done; IFS=" "; It's running fine with the usual rights, but if I run it ...

Textmate not picking up PATH

Textmate does not source my .profile file. I don't have a custom bash_init.rb, nor do I have a .bash_profile or .bash_login in my home directory (the other two files it checks first). My .profile gets sourced properly when I start up terminal ...

Testing bash scripts

We have a system that has some bash scripts running besides Java code. Since we are trying to "Test Everything That Could Possibly Break" and those bash scripts may break, we want to test them. The problem is it is hard to test the scripts. Is there a way or a best practice to test bash scripts? Or should we quit using bash scripts and...

How do I create a directory on remote host if it doesn't exist without ssh-ing in?

I'm not sure if this is possible or not, Basically, I'm writing a script that allows me to scp a file to my hosting. This is it so far. Arg 1 is the file and arg 2 is the folder i want it to be placed in on the remote server function upload { scp $1 [email protected]:$2 } As you may/may not know, if the directory I specify wh...

What is the fastest way to find all the file with the same inode?

The only way I know is: find /home -xdev -samefile file1 But it's really slow. I would like to find a tool like locate. The real problems comes when you have a lot of file, I suppose the operation is O(n). ...

Bash scripting call to AWK

I'm having difficulty getting the awk command inside a bash script to work. The script follows: #!/bin/bash fpga-test -1 -a $1 > tmp.file && awk \'\/Read\/ {print \$2}\' tmp.file When I run the command I get the following error. # my_script 14 awk: cmd. line:1: Unexpected token The intermediate file (tmp.file) looks like this, an...

BASH: error message does not get redirected to file

I have a bash script that simply calls different calls and redirect stdout and stderr outputs to different files. I've done this: command 1> datafile 2>> errorfile However, when the command is erroneous (e.g. wrong username and password combination given as arguments), the error message does not get redirected to the errorfile. I sti...

BASH: Merging multiple files given different file name prefixes in an array

After looking at this post, it looks like I can just use cat to merge files. However, I am a bit confused on how to do this with my array of filename prefixes. For example: prefixes=( pre1 pre2 pre3 pre4 pre5 ) If I have an array of prefixes like that, how can I make a command to look like this or do something similar to this: cat p...

Linux command line: split a string

Hi, I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c/...

bash/mysql complains about ) character

I'm trying to execute this: $ mysql --user=XXX --password=XXX --batch --skip-column-names \ -e "SELECT userid, displayname FROM Users" stackoverflowdb | \ split -l 50 -a 5 - "result." but bash complains about ) 'unexpected' character (i have this character and few other 'weird ones' in my mysql password). I tried to take my password ...

Automatically "Press Enter to Exit" in bash?

In a bash script, I'm using wine to call a DOS program that requires me to "Press Enter to exit". How do I do that automatically and continue with the rest of the script? ...

Uploading large files to a cluster of servers

Hi there, We have a cluster of 4 web servers which contain a few domains, one of which contains quite a lot of videos. We also have a 'staging' server which we usually sync/upload files to and then from there rsync them all out via a bash script to the other web servers. The problem we have is that quite a bit of this is manual. If in ...