LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2004, 07:37 AM   #1
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
Problem in shell script


Hi Everyone,
I am writing a shell script which reads another shell script one line at a time and executes them and if an error is encountered, it logs them in a log file. The shell scripts are as follows -

1. main script
-------------------------------------------------------------------------------------------------------------------------
#!/bin/sh


FILE=./tmpscript

LOGFILE=./log.txt

i=1;
declare -a name
num=`cat $FILE|wc -l`


{
while [ $i -le $num ]; do
read name[$i]
${name[$i]}

if [ $? = 1 ]
then echo [`date`] - $FILE :$i - ${name[$i]} Failed >>$LOGFILE
fi

let i+=1
done
} < $FILE
--------------------------------------------------------------------------------------------------------------------------

2. tmpscript
--------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
ls
echo "running test script"
echo "tests" > logic.txt
ls -l
ls kumar
# line of comment
--------------------------------------------------------------------------------------------------------------------------

So, the main script executes the script tmpscript one line at a time. Now the problem is the when it tries to run echo "tests" > logic.txt (line 4 of tmpscript), it does not execute properly. It is executed as "test">logic.txt and not as echo "test">logic.txt at the prompt and hence the logic.txt is not created. Can anyone please suggest me a solution for this.

Thank You

Kumar

Last edited by Kumar; 04-27-2004 at 07:42 AM.
 
Old 04-27-2004, 08:06 AM   #2
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
Perhaps if you change tests to something else (Tests perhaps) it will work.
 
Old 04-27-2004, 08:20 AM   #3
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Original Poster
Rep: Reputation: 15
I tried echo "12345">logic.txt and it didn't work...... The problem is while executing the command, the echo "12345" is executed first and hence the command becomes "12345" >logic.txt which is not proper . The whole command should execute at the same time
 
Old 04-27-2004, 08:41 AM   #4
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
Ah, I missed that tests is a script, the output of which you want in logic.txt. Try changing the line to tests > logic.txt , i.e. without the echo.
 
Old 04-27-2004, 08:48 AM   #5
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Original Poster
Rep: Reputation: 15
No ....actually my aim of using this command (echo "12345">logic.txt) is to create a temporary file during runtime which is to be used for further testing purpose . Thanks again for your answer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
A problem about a shell script jpan Linux - General 2 01-19-2005 06:14 PM
Shell-Script Problem? x4v013 Slackware 7 09-17-2003 12:15 AM
shell script problem steltner Linux - General 19 05-18-2003 02:42 PM
shell script problem steltner Programming 0 05-17-2003 03:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration