Need help redirecting output to a file including errors


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Need help redirecting output to a file including errors

Need help redirecting output to a file including errors if any,I have 2 script namely push.ksh and run.ksh, I'm scp'ing push.ksh to another server and executing remotely via run.ksh, the script run.ksh runs locally but does not capture any errors in "servername.out" file (I tried testing various failed conditions like the one below in push.ksh )and always echoes the message "echo "INFO: No Errors found" from run.ksh and moreover I could only see 'uname -n' and 'ls -ltr awk 'NR!=1 && NR!=2 {print $5}' values in servername.out (ofcourse this file is local)even though I'm redirecting both stderr and stdout

push.ksh
Code:
#!/bin/ksh

echo "`uname -n`"

echo "`ls -ltr awk 'NR!=1 && NR!=2 {print $5}'`

ls -l /jdfkds # to test fail condition

if [ $? -ne 0 ];then
	echo "ERROR: Unable to list files"
else
	echo "INFO: Files listed successfully"
fi

run.ksh
Code:
scp <servername> "/tmp/push.ksh"
if ssh <servername> "/tmp/run.ksh 2>&1" | tee "servername.out";then

	if grep -q -i "ERROR" "servername.out";then
		echo "ERROR: Errors found"
	else
		echo "INFO: No Errors found"
	fi
else
	echo "INFO: Success"
fi


Last edited by Scott; 10-09-2011 at 10:04 AM.. Reason: Code tags
# 2  
push script had errors!

push.ksh
Code:
#!/bin/bash
uname -n

#what is this line supposed to do?
#echo "`ls -ltr awk 'NR!=1 && NR!=2 {print $5}'`

ls -l /jdfkds # to test fail condition

if [ $? -ne 0 ];then
  echo "ERROR: Unable to list files"
else
  echo "INFO: Files listed successfully"
fi

--ahamed

---------- Post updated at 03:37 PM ---------- Previous update was at 03:34 PM ----------

run.ksh
Code:
#!/bin/bash

if ssh <servername> "/tmp/push.ksh 2>&1" | tee "servername.out"
then
  if grep -q -i "ERROR" "servername.out";
  then
    echo "ERROR: Errors found"
  else
    echo "INFO: No Errors found"
  fi
else
  echo "INFO: Success"
fi

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
# 4  
Ahamed:
Thanks for correcting the typos it should have been the below line in push.ksh, it just prints the file or directory names and also /tmp/push.ksh in run.ksh script:
echo "`ls -ltr | awk 'NR!=1 && NR!=2 {print $9}'`"

COKEDUDE:I tried different variations to redirect stdout and stderr with/without tee but for any condition it just goes straight to echo "INFO: No Errors found" part instead of "ERROR: Errors found" whenever it encounters the errors.
# 5  
so we good? are you able to proceed?

--ahamed
# 6  
I just had the typos while posting the script here and still having same issues as replied to COKEDUDE in my previous reply.
# 7  
Can you execute push.ksh in the remote server and see if it working?

And the syntax is incorrect. If you want to print it, it should be
Code:
ls -ltr | awk 'NR>2 {print $9}'

--ahamed
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #374
Difficulty: Easy
In 2004, a new edition of the POSIX:2002 standard was released called POSIX:2004 (formally: IEEE Std 1003.1-2004).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output to file

Hi, I have created script which redirect the output to file.I am able to get the output in file but not in the format. Output :Content of the log which have 10 -15 lines. Actal :Line1 ..Line 2Line3 Line4 Line 5 Expected:Line1 Line 2 Line3 Please... (7 Replies)
Discussion started by: karthik771
7 Replies

2. UNIX for Dummies Questions & Answers

Help with redirecting output to an HTML file

I'm very new to shell scripting and am practicing how to write a script, then redirect the output into an HTML file, and then email both the script and the HTML file to myself. I have created a script called sysinfo_page, and thought it would have redirected the output into the sysinfo_page.html... (3 Replies)
Discussion started by: braing
3 Replies

3. Shell Programming and Scripting

Redirecting output to file through cron

Hi Does anyone have any suggestions for capturing the output into a file when i run it through cron? I have file called "quick.1" which contains two simple commands to be executed on the target host. And i have second file called "quick.2" which contains the wrapper script to ssh to the target... (1 Reply)
Discussion started by: chandika_diran
1 Replies

4. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

5. Shell Programming and Scripting

Redirecting output of Make to file

Hi, I am unable to get this script to work as desired. Basically, if an argument "log" is sent into the script, it outputs the result of the Make to a file output.log. However, if the argument is not passed, I want the output to be just put on screen (no redirection). See code snippet below. #... (3 Replies)
Discussion started by: srujan45
3 Replies

6. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

7. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

8. Shell Programming and Scripting

Redirecting my output to a specific file

Hi guys am doing some checking inside my script and i want to redirect my output to a specific file for example checking if a move was successfully done and was writing on the screen whether the move was successful or not and now want to write same thing into a file... I am new to shell... (2 Replies)
Discussion started by: Lutchumaya
2 Replies

9. UNIX for Dummies Questions & Answers

redirecting output, including errors

what's the proper syntax to redirect output, including all errors? ls -la > direct.list makes out put file direct.list but if i'm running a script and i want to include the errors, would i type something like: myscript.scr 2> out_list.txt or will that get the errors only? (1 Reply)
Discussion started by: kymberm
1 Replies

10. UNIX for Advanced & Expert Users

redirecting output to file in network

Hi Experts, Is it possible to redirect the output of an unix command to file. when i "telnet" to a remote system and execute the redirection operation, such that the result should outputted to my system. $ telnet IPaddr2 username : zzzzz password : ******** IPaddr2>ls > file <- i... (1 Reply)
Discussion started by: anent
1 Replies

Featured Tech Videos