Invoking CGI executable after setenv (in bash)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Invoking CGI executable after setenv (in bash)
# 8  
Old 02-26-2009
Code:
export var=value

# 9  
Old 02-26-2009
Quote:
Originally Posted by aplaydoc
Sorry, here it is:

This isn't PHP code, why call it that?
Quote:
Code:
#!/bin/bash

##First I define some variables:
Executable=/u/myname/someplace/SomeProgram.cgi
WorkDir=/u/myname/here/there
subdirName=XYZ
NB1=5
NB2=1000

for ID in `ls $WorkDir`; do


Not only is ls unnecessary, but it will break your script if any filenames contain spaces or other pathological characters.

Code:
for DIR in $WorkDir/*/$subdirName/

Quote:
Code:
        #Define some variables specific to this iteration
        DIR=$WorkDir/$ID/$subdirName/


That is unnecessary if you use the line I suggested above.
Quote:
Code:
        OutFile=${DIR}somefile.txt

        export QUERY_STRING "workdir=$DIR&nb1=$NB1&nb2=$NB2"

Code:
export QUERY_STRING="workdir=$DIR&nb1=$NB1&nb2=$NB2"

Quote:
Code:
        #call the executable, I extract some lines from its output,
        # and I fix them with perl regexprep:
        $Executable | tail -$(( $NBCLUSTERS*2+6 )) |
          head -$(( $NBCLUSTERS*2+4 )) |
           perl -pi -e 's/<b>|<\/b>//g' > $OutFile
        echo "Done!"
done

# 10  
Old 02-26-2009
Quote:
Originally Posted by vgersh99
export [-fn] [name[=word]] ...
I just noticed the = in red, sorry! I changed my line into

export QUERY_STRING="workdir=$DIR&nb1=$NB1&nb2=$NB2"

and now everything seems fine.

Strange that before I didn't get any errors (strange and dangerous too!!)
# 11  
Old 02-26-2009
Thanks guys for the help, I greatly appreciate it.

Is there a better way to strip out <b> and </b> symbols from the piped output besides calling perl?

Code:
$Executable | tail -$(( $NBCLUSTERS*2+6 )) | head -$(( $NBCLUSTERS*2+4 )) | perl -pi -e 's/<b>|<\/b>//g' > $OutFile

(By the way, I just click on the PHP button where I'm typing the message to capsulate my code, not because my code is PHP, now I just wrote [ code ] and [ /code ] manually)


As for using
Code:
for ID in `ls $WorkDir`; do

my reason is that I want to echo $ID on the screen after every iteration...

Code:
for ID in $WorkDir/*; do

gives the full directory name where $ID exists, so I will need to strip everything before the last /

Last edited by aplaydoc; 02-26-2009 at 09:05 PM..
# 12  
Old 02-26-2009
Code:
echo 'foo <b>bar</b> <b>fred</b>' | sed -e 's#<b>##g' -e  's#</b>##g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script make itself executable

Is there a way to make this make itself executable? Thanks. :-) cat > somescript.sh << \EOF #!/bin/bash block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Block count:/ {print $NF}') reserved_block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Reserved block count:/ {print $NF}') perl -e... (4 Replies)
Discussion started by: drew77
4 Replies

2. Programming

Calling bash script from CGI

Hi, I am having two individual scripts Script 1): CGI script - is a simple script which trigger bash script Script 2): Bash script - is a script which execute which collects file system utilization information from all the Unix servers If I am executing CGI script manually from command... (2 Replies)
Discussion started by: Naveen.6025
2 Replies

3. Shell Programming and Scripting

Bash scripts - CGI and ssh

Hi Everyone, I started looking at the possibility of making some of our bash scripts available through a web server using CGI and the simple ones works just fine. Now I need to execute remote commands using ssh but can't really get it to work. I got private keys all sorted. Must be ssh... (1 Reply)
Discussion started by: arizah
1 Replies

4. Shell Programming and Scripting

Invoking a bash shell with an export var

Hello all, How can I invoke the bash shell (via command line) to execute another command by setting an exported environmental variable on the fly (as this env var would be used by the command -another script, the bash would execute). This needs to be done in one single line as the same would... (4 Replies)
Discussion started by: Praveen_218
4 Replies

5. Shell Programming and Scripting

Running an executable from bash prompt

Hi, I'm trying to run a program from the bash prompt and I don't understand why it is returning with an error. Dig is my C program, and it takes in parameters J4, detect, 3 and 0182F98E var1="cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig J4 detect 3 0182F98E" when I do ... (6 Replies)
Discussion started by: oahmad
6 Replies

6. UNIX for Dummies Questions & Answers

Running Executable in Bash Script

Hey guys, so I've been trying to write a bash script called runSorter.sh that runs an executable that also takes in some parameters and outputs the results to a text file. The executable, sorter, takes in a number parameter. I want to make it so that you can input as many number parameters into... (4 Replies)
Discussion started by: Duo11
4 Replies

7. Shell Programming and Scripting

Delete Files with CGI Bash Script

Hi. I could use some help with my problem. I am creating a website. One option on this website is to delete a specified file, say an image, when the user clicks on it. I want to do this with CGI. I believe bash will be the easiest since I will just type the command "rm file". I also do not know... (4 Replies)
Discussion started by: JMooney5115
4 Replies

8. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

9. Shell Programming and Scripting

Wrapping a bash script for CGI

I hope its ok to start a new thread, I was going to use my existing one but thought a new one would better clarify things and provide better search for future reference. Well I have my bash program working now, all nice, user input validated, output formatted, everything is looking sexy. Now... (2 Replies)
Discussion started by: andyj
2 Replies

10. UNIX for Dummies Questions & Answers

How do I make a cgi script World-executable

I'm trying to set up a form mail script on a website that when Submitted, a cgi script is executed and a perl translator (located in a secured and inaccessible folder) translates the script. After speaking to my hosting provider, I was told to "Telnet into the system and make the script... (2 Replies)
Discussion started by: tylerl
2 Replies
Login or Register to Ask a Question