shell-scripting

Replace a text by shell programming

i have more than 1000 files and want to replace a special text in all of them with another phrase. how can i do it by shell script in linux? ...

How to echo text and have output from a command be sent to a file in parallel

I would like to echo text and also remotely ping a computer and have the output be sent to a log file. I also need to do this in parallel but I am having some trouble with how the output is being sent into the log file. I would like the output to look like: host | hostTo | result of ping command but since I have this running as a back...

What does '-a' do in Unix Shell scripting

What does -a mean in the below line. if [ "${FILE_SYSTEM}" != "xyz" -a "${FILE_SYSTEM}" != "abc" ] ...

Problem with run commands in shell (bash) with arguments as variables !

Hi all ! (Sorry for the confusion. Previous $ sign occurred when I tried to simplify the actual problem. Thanks for correcting the question) I wanted to split a directory name on underscores (ex: dir_to_split="my_test_dir") like this: my_dir=($dir_to_split) var=$(echo $my_dir | awk -F"_" '{print $1,$2,$3}') set -- $var splited_1=...

Ignoring the forward slash in a shell script

Hello wonderful computing persons, This is really simple and I hope I'm not being redundant. I'm writing a shell script with this command: sed -e 's/OLD_ITEM/NEW_ITEM/g' but I actually want to do something that includes a directory: sed -e 's/FOLDER/OLD_ITEM/NEW_ITEM/g' how do ignore the forward slash so that the entire line FO...

shell scripting: get a specified range of parameters

I normally come here if google doesnt work. So this time it goes like this: In a function, i want to assign to a variable from the 4-th input parameter onward. Example: function foo { var="$4$5$6..." use var commands using $1, etc } So i think i cannot use shift, since i want to use $1 afterwards. I do not either want...

Run a shell script on all files within a directory and its sub-directories

Good evening fellow computational authors, I'm trying to run the following script: find . -name '*.php' -exec /search_replace.sh {} \; so that it runs search_replace.sh on all the .php files in a folder and its sub-folders. I keep on getting the error: find: /search_replace.sh: No such file or directory Any assistance? ...

parse json with shell scripting at linux

I have a JSON string like the example below and I want to use, for example, the value of the "uptime" command as a variable in a shell script, what should I do? { "serverStatus" : { "version" : "1.6.0", "uptime" : 527, "uptimeEstimate" : 526, "localTime" : { "$date" : 1286923624579 }, "globalLock" : { "totalTime" : 526604302, "lockT...

Shell script to backup databases of users

I have the shell script which first goes in home directory and backups all folders like OCT-13-2010/username/homebck.tar.gz and i also backups the database ,ef if i am in user1 folder then all my databases are like username_web and i use the following to backup mysqldump --skip-lock-tables -u sqluser -ppassword --skip-extended-inse...

How to break the string in shell script

I have the databases name in following format username_databasename Now I want to put separate database backups in username directory like /backups/username/backup How can I get the usernamae from that string I also want that if string does not contain underscore (_) then the backup should go to /backups/others/backup ...

How To remove an item from Login Items using shell script

Hi, In Mac, I want to remove an application from the login items using Shell script. I tried following code, but didn't work.. defaults write loginwindow AutoLaunchedApplicationDictionary -array-remove path "/Applications/myApp.app" But it is giving error "Unexpected argument -path; leaving defaults unchanged" Regards, Dhanara...

find without recursion

Hi there, is it possible to use a the find command in some way that it will not recourse into the sub directories? e.g. DirsRoot |-->SubDir1 | |-OtherFile1 |-->SubDir2 | |-OtherFile2 |-File1 |-File2 And the result of something like find DirsRoot --donotrecuourse -type f will be only File1, File2 ? Anyone knows a way...

Problem with backticks in shellscript

I am having a problem getting my shellscript working using backticks. Here is an example version of the script I am having an issue with: #!/bin/sh ECHO_TEXT="Echo this" ECHO_CMD="echo ${ECHO_TEXT} | awk -F' ' '{print \$1}'" result=`${ECHO_CMD}`; echo $result; result=`echo ${ECHO_TEXT} | awk -F' ' '{print \$1}'`; echo $result; The...

Is there a way to have Ant create a shell or batch runtime script?

Is there a way to have Ant create a runtime shell or batch runtime script instead of having to manually create the script myself. It would be similar to the functionality of link text ...

How to make files in Linux folder with default group write permission

I have the folder called backups. The root is putting backups in that folder. I want that all the files which are created in that folder should have group write permission. I know i can use umask but i want to know that will umask work for all the files any where or it will work on particular folder. e,g i want umask for only /backups ...

Is it possible to set variables equal to expressions in UNIX?

In Unix, how would one do this? #!/bin/sh x=echo "Hello" | grep '^[A-Z]' I want x to take the value "Hello", but this script does not seem to work. What would be the proper way of spelling something like the above out? ...

Reverse the contents of each line in a file?

I was hoping someone could help me, I need to reverse the contents of each line in a file. So basically this: 101.228.168.192 to 192.168.228.101 Is there a command I could use in a bash script, or even just the logic needed to get the job done. Thanks ...

How to read in arguments passed via ant to testng.xml

Hey Guys, Here is the scenario: Have a shell script that calls ant with one argument. The ant in turn executes testng.xml (suite file) passing the same argument and testng in turn executes the test within passing the same argument. In my case, I am passing the browser string eg.(firefox, iexplore) argument that will specify which brow...

How to use ssh command in shell script?

I know that we shuld do ssh user@target but where do we specify the password ? Thanks for your help ! Lalith ...

Run command line arguments in python script

I have a program that is run from the command line like this python program.py 100 rfile How can I write a new script so that instead of running it with just the '100' argument, I can run it consecutively with a list of arguments like [50, 100, 150, 200]? Edit: The reason I am asking is that I want to record how 'program.py' executes...