works from cmd-line but not in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting works from cmd-line but not in script
# 1  
Old 10-18-2006
works from cmd-line but not in script

hi
I'm trying to query a directory, check it's the right directory, return the results into a text file, put text file into an array and navigate the subdirectories and delete contents.

find `pwd` -type d | grep TESTINGDIR > dirList.txt

The txt file is created from the cmd-line but not in my script
Any ideas anyone?
Thanks
# 2  
Old 10-18-2006
TESTINGDIR is a variable or constant in your case, as well as try to run the script without redirecting output to a txt file and see what you get on the screen, and also post here the error which you get at run-time.
# 3  
Old 10-18-2006
Hi shereenmotor
thank you
without redirect to txt file i get the dir listing echoed back to me.

when I keep the redirect I get no error message at all and nothing is written to my dirList.txt file.
when I put
find `pwd` -type d | grep TESTINGDIR 2> dirList.txt

I get the dir listing redirected to stdout i.e. echoed back to me
# 4  
Old 10-18-2006
Quote:
Originally Posted by OFFSIHR
find `pwd` -type d | grep TESTINGDIR 2> dirList.txt
With the above command, you are not redirecting standard output to dirlist.txt, its telling shell to redirect any errors(fd2) to dirlist.txt and standard output is redirected no where, therefor you are getting output echoed back at your screen, change your command as follows:
Code:
find `pwd` -type d | grep TESTINGDIR 1> dirList.txt

and see what you get.
# 5  
Old 10-18-2006
Hi shereenmotor
thank you, this works from command line but does not from within the shell script.
I think i will just implement it differently
thank u for your time
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Works on command line but not in script

OSX 10.9 I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently. Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly? ... (1 Reply)
Discussion started by: sudo
1 Replies

2. Windows & DOS: Issues & Discussions

Command works on CMD line but not in batch?

Hi All, This command works when I type it on but when I run the batch file it doesn't..any ideas why? attrib.exe * | find /c /v "" >filecount.txt (1 Reply)
Discussion started by: Grueben
1 Replies

3. UNIX for Advanced & Expert Users

SSH key works from CMD line not script

OK , .. This is an odd one. I have a new server and I need to have a tunnel open to it. I have this exact process running on a few others but this new one I just got is not allowing the script to connect. I set up my users account and ssh keys from the server that will host the tunneling i... (6 Replies)
Discussion started by: jeffsandman0035
6 Replies

4. UNIX for Dummies Questions & Answers

Works on command line but not in script

Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it. I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working. grep -rl... (4 Replies)
Discussion started by: anthonyjstewart
4 Replies

5. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

6. Shell Programming and Scripting

find cmd works different on cron job ?

/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime $DAYS_AGO -printf %f -printf "\n" | sort -r > $FILES The above command gives different results when run on a cron job. When run manually the result is accurate. (2 Replies)
Discussion started by: nuthalapati
2 Replies

7. Shell Programming and Scripting

This code works in the command line but not in a shl script

When I run this code from the command line works spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ ls ef* eftseq.dat spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ file_seq=$( < eftseq.dat) ... (1 Reply)
Discussion started by: rechever
1 Replies

8. Shell Programming and Scripting

Zgrep works at command line but not in script?

Hi all- I'm trying to search through some .gz log files to verify certain feeds have passed through our app. I have a small script that I wrote in hopes that I could automate the checking but haven't been able to get the zgrep to work. When I copy it to the command line directly it works... (2 Replies)
Discussion started by: Cailet
2 Replies

9. Shell Programming and Scripting

telnet shell script on red hat 9 cmd line only

i would like to make a shell script (red hat 9 cmd line only) to telnet to my local isp's webmail server on port 25 and send it commands such as helo :) help would be much appreciated, and i found no posts similar that answered my question... the closest i've gotten to an answer from about 8... (3 Replies)
Discussion started by: kypeswith
3 Replies

10. UNIX for Dummies Questions & Answers

script works on command line, not in cron job

Hey there, I'm a total newbie unix guy here and just picking this stuff up. Have a very small script I put together that works fine from the command line but not once I put it in a cron job. Searched and found this thread and am wondering it it has something to do with setting variables, though the... (7 Replies)
Discussion started by: JackTheTripper
7 Replies
Login or Register to Ask a Question