Why Does Command Run From Prompt But Not From Script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why Does Command Run From Prompt But Not From Script?
# 8  
Old 09-17-2008
Quote:
Originally Posted by jim mcnamara
If it is "hanging" it is probably waiting for a response to the "Password:" prompt. Are you running the script as the root user?
It's not being run as root but it is using IDs that have been configured with a trusted user status that permits communication between the servers without password prompts.
# 9  
Old 09-17-2008
What is the output of set (or env) from inside the script and on the command line - any diffs?
# 10  
Old 09-17-2008
Quote:
Originally Posted by jim mcnamara
What is the output of set (or env) from inside the script and on the command line - any diffs?
A comparison of ENV from inside the script and the command line show no differences.
# 11  
Old 09-17-2008
Post the output of cat -vet on your script...I'm leaning towards control characters embedded in your script.
Code:
cat -vet script

# 12  
Old 09-17-2008
I found something interesting just now. I thought that perhaps the problem was with the AWK command. I don't use it much and it always seems to give me a hard time so I'm naturally skeptical of it.Smilie

So I took it out and replaced it with a grep command. Grep won't do what I need because it can't sort columns based on a delimiter but it's close enough to test this problem with. The new line was now:
su userID -c
remsh server -l userid -n grep SMITH /tmp/infromational/version74b/LIVE/TEMPORARY/ABCfiles/HLC_Database_File.bat|head -1 > /tmp/variant/45BV32/var/store13.logfnd


Now, at first this still hung until I changed the whole thing to a single line:
su userID -c "remsh server -l userid -n grep SMITH /tmp/infromational/version74b/LIVE/TEMPORARY/ABCfiles/HLC_Database_File.bat|head -1" > /tmp/variant/45BV32/var/store13.logfnd

That worked but I can't seem to make it the same when I use AWK because AWK requires quotes around itself that grep doesn't and remsh when used on the same line as the SU command requires quotes around itself as well. So it ends up looking like this:
su userID -c "remsh server -l userid -n "awk -F^ '\$4 == \"SMITH\"' /tmp/infromational/version74b/LIVE/TEMPORARY/ABCfiles/HLC_Database_File.bat|head -1"" > /tmp/variant/45BV32/var/store13.logfnd

but that many quotes just do not work in the script.
su: illegal option -- F
su: illegal option -- ^
-F^: bad option(s)


And if I remove the quotes from around the AWK command I get this error:
syntax error The source line is 1.
The error context is
>>> == <<<
awk: Quitting
The source line is 1.


And if I remove the quotes from around the remsh call instead I get this error:
su: illegal option -- l
su: illegal option -- n
usage: remsh host [ -l login ] [ -n ] command
# 13  
Old 09-17-2008
Quote:
Originally Posted by shamrock
Post the output of cat -vet on your script...I'm leaning towards control characters embedded in your script.
Code:
cat -vet script

The result of cat -vet are as follows:
su userID -c$
remsh server -l userid -n "awk -F^ '\$4 == \"SMITH\"' /tmp/infromational/version74b/LIVE/TEMPORARY/ABCfiles/HLC_Database_File.bat|head -1" > /tmp/variant/45BV32/var/store13.logfnd$
# 14  
Old 09-17-2008
So no control characters but you seem to have isolated fault with awk command. I have made minor tweaks to it in red. Removed backslash in \$4 and the ones in \"SMITH\".

Code:
su userID -c \
"remsh server -l userid -n "awk -F^ '$4 == "SMITH"' /path/to/input/file | head -1"" > output_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

2. Shell Programming and Scripting

Shell script prompt for first parameter ($1) then run

I have to run post configuration script like this script file is post_config.sh post_config.sh 1234 #1234 is node ID according to given node ID all script run .. .. But i want to post_config.sh script should ask for node ID then run like this.. post_config.sh #i want to run... (8 Replies)
Discussion started by: Ganesh Mankar
8 Replies

3. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

4. Shell Programming and Scripting

Use Unix shell script to open Windows command prompt (cmd)

Hello, I work on Windows and I use Putty to access a remote UNIX server. I am trying to build a shell script that will have as main task to open the Windows command prompt (cmd) and run some Windows commands thereafter. The commands are actually file transfer commands that will download a file... (14 Replies)
Discussion started by: rookie2785
14 Replies

5. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

6. AIX

Command behaves different in script and on prompt

$cat /tmp/tuxob.lst udi ***** jim 10 ant 19 ibm ***** $ input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'` $ echo $input The output I am expecting is '*****'. But It is showing me the available files of current directory. When I run the command head -1 /tmp/tuxob.lst | awk '{print $NF} ... (3 Replies)
Discussion started by: panchpan
3 Replies

7. Shell Programming and Scripting

script submitted using ssh does not return to command prompt

Gurus, I have written a shell script to backup a database and applications. This is how the script works: 1. As applications user (say applmgr), the main backup script, say backup.sh, is kicked off. 2. backup.sh does ssh to oracle user and kicks off the database backup using nohup and... (1 Reply)
Discussion started by: sunpraveen
1 Replies

8. UNIX for Dummies Questions & Answers

running command prompt executable file in shell script

hi i have file extentioned with test.vbs. i am able to run this file n execute through command promt but i dont know how to run in shell script example: file name is test.vbs which contains strSoundFile = "C:\windows\Media\Notify.wav" Set objShell = CreateObject("Wscript.Shell") strCommand... (5 Replies)
Discussion started by: atl@mav
5 Replies

9. Shell Programming and Scripting

Command prompt from within a script?

I am writing a menu script and one of the options is to access a Command Prompt and return to the menu via CTRL-D. I have tried using a loop and echoing the PS1 value, then using read to assign whatever is entered into a variable, then executing the value of that variable as a command using .... (1 Reply)
Discussion started by: sanitywonko
1 Replies

10. Shell Programming and Scripting

script to go to a different dir to run a commandline prompt in that dir

Hi, I need to know how I'll be able to write a script that can goto a different dir where I don't have access to read,write and execute and also to run a commandline prompt in that dir with one file whose path has to be specified in that command. Will I be able to do this? Any ideas or... (2 Replies)
Discussion started by: ann_124
2 Replies
Login or Register to Ask a Question