Help Syntax Shell-Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Syntax Shell-Script
# 8  
Old 08-13-2009
Code:
 
/usr/bin/php5 script1.php >/tmp/script1.$$
if [ -s /tmp/script1.$$ ]
then
echo 'Script 1 was not read - Error'
cat /tmp/script1.$$
else
echo 'Script1 read - Success'
fi
rm -f /tmp/script1.$$
 
/usr/bin/php5 script2.php >/tmp/script2.$$
if [ -s /tmp/script2.$$ ]
then
echo 'Script2 was not read - Error'
cat /tmp/script2.$$
else
echo 'Script2 was read - Success'
fi
rm -f /tmp/script2.$$
 
/usr/bin/php5 script3.php >/tmp/script3.$$
if [ -s /tmp/script3.$$ ]
then
echo 'Script3 was not read - Error'
cat /tmp/script3.$$
else
echo 'Script3 was read - Success'
fi
rm -f /tmp/script3.$$



and my Log:
Code:
 
Thu Aug 13 12:34:09 CEST 2009
Script 1 was not read - Error
Can /srv/www/htdocs/_source/xml-file not read.Script2was read - Success
Script3 was read - Success

Is there a chance that the formatting is:
Code:
 
Script 1 was not read - Error - Can /srv/www/htdocs/_source/xml-file not read.
Script2 was read - Success
Script3 was read - Success


I tried a few versions, but none of them matched ...
# 9  
Old 08-13-2009
You only need echo "\n" after the cat comand
Code:
cat /tmp/script1.$$
echo "\n"
......
cat /tmp/script2.$$
echo "\n"

try this, i think is more clean and optimal code :
Code:
for num in 1 2 3
do
          /usr/bin/php5 script${num}.php >/tmp/temp_scrip.$$
    if [ -s /tmp/temp_scrip.$$ ]
    then
        echo 'Script${num} was not read - Error'
        cat /tmp/temp_scrip.$$
        echo "\n" 
    else
        echo 'Script${num} was read - Success'
    fi
done
rm /tmp/temp_scrip.$$

# 10  
Old 08-13-2009
Quote:
Originally Posted by chipcmc
You only need echo "\n" after the cat comand
Code:
cat /tmp/script1.$$
echo "\n"
......
cat /tmp/script2.$$
echo "\n"

Sorry, but this doesnīt work ... neither "\n" nor "-n" ...

Script:

Code:
 
/usr/bin/php5 Script1.php >/tmp/script1.$$
if [ -s /tmp/script1.$$ ]
then
        echo "Script1 was not read - Error"
        cat /tmp/script1.$$
        echo "\n"
else
        echo "Script1 was read - Success"
fi
rm -f /tmp/script1.$$

...
...
...

logfile:
Code:
 
Thu Aug 13 15:46:22 CEST 2009
Script1 was not read - Error
Can /srv/www/htdocs/_source/xml-file not read.\n
Script2 was read - Success

# 11  
Old 08-13-2009
Quote:
Originally Posted by jackcracker
Sorry, but this doesnīt work ... neither "\n" nor "-n" ...

[code]
logfile:
Code:
 
Thu Aug 13 15:46:22 CEST 2009
Script1 was not read - Error
Can /srv/www/htdocs/_source/xml-file not read.\n
Script2 was read - Success

Th problem is than echo comand print de characters \n and you want that interpret this characters, you need -e option in echo Smilie

man:
-e enable interpretation of backslash escapes

try this :
echo -e "\n"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with if statement syntax in shell script

I want to make the file test condition a variable ($Prmshn in code below). My goal is to use something like the first three unsuccessful if statetments since the 'if #!/bin/ksh test_input() { Prmshn=${1} InFLNm=${2} ifReq="-$Prmshn $InFLNm" #the following three if statments fail: #if ] ;... (10 Replies)
Discussion started by: ms63707
10 Replies

2. Shell Programming and Scripting

Help with Check Syntax of Shell Script without Running

Hi Everyone, Is there any way ( generic) to check syntax of Shell Scripts without running it?? (4 Replies)
Discussion started by: roy121
4 Replies

3. Shell Programming and Scripting

syntax error in shell script

I am creating a shell script. In which, I need to get server name and server IP. I used this command in script. servername=`cat /etc/hosts|grep `eval hostname`|awk '{print $2}'` however, when execute script or put set -x to debug, it return: line 13: syntax error at line 13: `|' unexpected... (4 Replies)
Discussion started by: duke0001
4 Replies

4. Shell Programming and Scripting

Syntax Error in Unix Shell Script

I am trying to run a unix script in my home directory.Snippet below echo "`date '+%Y%m%d_%H%M%S'` Getting ProductList.dat" if ( -f $DIR/ProductList.dat) then cp $DIR/ProductList.dat MigratedProductList.dat else echo "`date '+%Y%m%d_%H%M%S'`ProductList.dat does not exist; Processing... (4 Replies)
Discussion started by: Mary James
4 Replies

5. Shell Programming and Scripting

shell script | bc syntax format

sorry but need help http://i.investopedia.com/inv/articles/site/CalculationEMA.gif trying to achieve ema in script I have this syntax which errors ema=` ; the 0.153846154 ='s Smoothing Factor really appreciate help (3 Replies)
Discussion started by: harte
3 Replies

6. Emergency UNIX and Linux Support

Seek help on shell script syntax errors

I want to delete archivelog files that has been archived and applied from primary database to standby database. This piece of script is working in Linux server. However, I copy it to Unix server with tiny modification. It won't work and generate the error message. I have checked code carefullt... (8 Replies)
Discussion started by: duke0001
8 Replies

7. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

8. Shell Programming and Scripting

How to Check Shell script syntax w/o executing

Hello All, I looking for a way to verify the correction of shell script syntax. Is there any switch like -c in perl which do this in shell ? Thank You. (1 Reply)
Discussion started by: Alalush
1 Replies

9. Shell Programming and Scripting

Basic Shell script syntax help

Hi All, I am new to shell scripting. I have a variable which holds a numeric value.I have to check whether this variable holds a value between(0- 8),(8-17)(17-24).How do i write this syntax using if in shell scripting. Thanks Vignesh (2 Replies)
Discussion started by: vignesh53
2 Replies

10. Shell Programming and Scripting

Shell script syntax checker

I have a rather big script that i have written in ksh and it is falling over in two places with a 'test argument' error. I know this usually means that the if statement is not correct, but it is fine. I have looked through the rest of the script for any odd brackets or ` marks, but can't see... (2 Replies)
Discussion started by: handak9
2 Replies
Login or Register to Ask a Question

Featured Tech Videos