shell-scripting

Regarding shell script -env variables

Have a shell script that reads the files in a particular directory. #!/bin/bash for fspec in /exp/dira/test/ready/* ; do done I want to modify the unix shell script so that path is retreived from enviornmental variable. export CUST_DATA=${_FX_DATA_}/test have set this variable in environment thru .profile #!/bin/bash READY_FIL...

While loop never ends

I'm working with bash and I'm trying to do something like this: A=1 while [ $A=1 ]; do read line echo $line | grep test >/dev/null A=$? echo $A done This script never ends even when the grep finishes successfully and A is set to 0. What am I missing here? Below is a sample of the output. $ ./test.sh asdf 1 te...

How do I write a pidfile in a windows batch file

Hi! I am writing some Java code that needs to be able to write a pidfile on Unix-like as well as windows machines. On the unix machines I write out a bash shell script that contains something like this command 1>/dev/null 2>&1 & echo $! > pidfile It executes a command, redirects all output into nirwana and puts command into the backg...

Shell Script, Search File for String

I'm writing a shell script that opens a file and needs to find a tag like ##FIND_ME##. The string I'm searching for is a constant (and there is only ever one instance of it.) Once I locate that string, I need it to start a new search for a different string from that point forward. My *nix skills are a little rusty, should try to imple...

How do I some basic file I/O and run a quick XML query in PHP?

I need to run a complex series of commands in PHP, and I'm not sure about exactly how to do it. We have two executables we need to work with: generate to create a fruit basket. This generates an XML file. peel to peel a fruit by identifier. Generates a long string. There are basically 5 steps: First, system("generate ... > fruits.x...

Regarding UNIX Move Command Override Protection

Pasted a piece of code from the shell script transfer.sh if [[ ${ld} -eq ${eld} ]] ; then mv "$file1" "$FILESNEW/." if [ $? -ne 0 ]; then echo "Move Command Failed-File ${fspec}" fi echo "File ${fspec} Sucessfully Moved to ready directory " else e...

Writing shell script to scan a list of folders

I have a file folders.txt one two three four ... that has a list of folder names. [one, two, three and four are names of folders]. Each of these folders has a number of files of different types (different extensions). I want a list of all the files in all the folders of one particular extension, say .txt. How should my shell script ...

What are the syntax changes from the shell script to the cshell script?

I just came to know that .sh files don't use set and spaces around = are not allowed, while this is allowed in a .csh file. Is there some place that you can point me to where I can find all these minor differences? ...

Awk to replace single quote

Hi I am stuck with this I want to replace all include('./ in a set of files with include('. I am trying to use awk as follows: awk '{gsub("include\('"'"'./", "include\('"'"'", $0); print > FILENAME}' *.php It throws me this error. awk: (FILENAME=xyz.php FNR=1) fatal: Unmatched ( or \(: /include('.// Any help would be appreciated....

Can a shell script indicate that its lines be loaded into memory initially?

This is a little thing that bothers me every now and then: I write a shell script (bash) for a quick and dirty job I run the script, and it runs for quite a while While it's running, I edit a few lines in the script, configuring it for a different job But the first process is still reading the same script file and gets all screwed up. ...

Meaning of Perlis's Epigram #22

From Epigrams in Programming by Alan J. Perlis: 22. A good system can't have a weak command language. What does this mean? What are good examples of this principle? Where can I learn more on how to implement a command langauge that meets this criteria? ...

linux shell scripting kiddie's question

an Unix shell script with only purpose - count the number of running processes of qmail (could be anything else). Easy thing, but there must be some bug in code: #!/bin/bash rows=`ps aux | grep qmail | wc -l` echo $rows Because echo $rows always shows greater number of rows (11) than if I just count rows in ps aux | grep qmail T...

How to run a python script without specifying the file extension (cross platform solution)?

Let's say that we have a Python script do.py and we want to be able to call it without extension, like do or ./do. If we rename the file from do.py to do and assure we have a valid shebang line it will work for all platforms but Windows. On Windows there is no way of executing file without extension. On Windows, if we keep the origina...

Linux file installer for a file that runs on start up.

My goal is to use a script that will install an executable file on Linux (Busybox variant). The target file should run when the computer starts, so in the rc.sysinit file, I'll have a line like the following: /usr/bin/foo & Now, when I run the install script, that line may or may not already be present (depending if the file had been ...

How to get extension of a file in shell script

Hi all, I am trying to get file extension for a file in shell script. But without any luck. The command I am using is file_ext=${filename##*.} and file_ext = $filename |awk -F . '{if (NF>1) {print $NF}}' But both of the commands failed to put value in variable file_ext. But when i try echo $filename |awk -F . '{if (NF>1) {print...

how to manipulate array in shell script

Hi I want my script to define an empty array. array values should be added if predefined condition gets true. for this what i have done is declare -a FILES file_count=0 if [ "$file_ext" != "$SUPPORTED_FILE_TYPE" ] ; then echo "$file_ext is not supported for this task." else $FILES[$file_count] = $filename file_c...

bash script running string as command

i have a bash script that builds a string to run as a command the script: #! /bin/bash matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/" teamAComm="`pwd`/a.sh" teamBComm="`pwd`/b.sh" include="`pwd`/server_official.conf" serverbin='/usr/local/bin/rcssserver' cd $matchdir illcommando="$serverbin include='$include' server...

Command-line parameters in Shell Script?

I am trying to include this du -s *|awk '{ if ($1 > 3000) print }' in a shell script, but I want to parameterize the 3000. However, since the $1 is already being used, I'm not sure what to do. This was a total failure: size=$1 du -s *|awk '{ if ($1 > $size) print }' How can I pass a parameter in place of 3000 in the first script ab...

Bash scripting, checking for errors, logging

Here's one for the bash-fu wizards. No, actually, I'm just kidding, you'll all probably know this except for me.. I'm trying to create a backup shell script. The idea is fairly simple: find files in a certain folder, older than 7 days, tar/gzip them to another directory, and remove them. The problem is, I'm not sure if I'll have enough ...

shell script to add list of domains to apache vhosts

I have a list of ~900 domains that I need to set up on a linux/apache server. It would be absolutely brutal to create all of the users/groups/vhosts by hand. Does anybody know of a resource that I could use to automate this? I guess the script should do these actions: Read text file line by line in to array For each item in array: User...