Ksh script: std Out/err


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ksh script: std Out/err
# 1  
Old 02-07-2011
Ksh script: std Out/err

Hello gurus, this is part of my script:

Code:
 
ls -1 ${MyFile} >> ${dir_log}ListFile${Now}.tmp
FILENUM=`cat ${dir_log}ListFile${Now}.tmp| wc -l | awk '{print $1}'`>> /dev/null
if [ ${FILENUM} -lt 1 ]
then
        writeError "ERRORE: no file in directory for type ${FileName}!" >> ${LogFileName}
        Close 1
fi

but although it tries to
Code:
"> /dev/null"

to video it always appears:

Code:
CR_CHR_GSM_*.data.gz: No such file or directory

How to make?
Thanks
# 2  
Old 02-07-2011
Try:
Code:
FILENUM=`cat ${dir_log}ListFile${Now}.tmp 2>/dev/null | wc -l | awk '{print $1}'`

# 3  
Old 02-07-2011
the same message:

Code:
 
CR_CHR_GSM_*.data.gz: No such file or directory

# 4  
Old 02-07-2011
Looking closer, the statement is dealing with filenames that end in .tmp and your error message is dealing with filenames that end in *.gz. So you are looking at the wrong statement. Maybe you need to put the redirect on the ls statement above it. Or more likely it's the wrong fragment of code entirely.
# 5  
Old 02-07-2011
Your code can be simplified as shown by the following simple example:
Code:
MyFile='CR_CHR_GSM_*.data.gz'

if [[ $(ls -l $MyFile 2>/dev/null | wc -l | tr -d ' ') > 0 ]]
then
   echo "true"
else
   echo "false"
fi

# 6  
Old 02-08-2011
always the same message!!!!!!

Code:
 
CR_CHR_GSM_*.data.gz: No such file or directory

# 7  
Old 02-08-2011
It appears cause it is an error, so you have to redirect your stderr, not your stdout.

Can you try :
Code:
$ ksh ./your_script 2> ./err_log
$ cat err_log

br/gb
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Keeping std & err outputs alive and feed one log file in a one-shot way

Bonjour, I have a large script with a lot of print statements and misc commands. Standard and error outputs are redirected like into the following code : #!/usr/bin/ksh LOG=/<some dir>/log > $LOG exec >>${LOG} 2>>${LOG} print aaaaa print bbbbb print ccccc ... some_cmd That way,... (5 Replies)
Discussion started by: Fundix
5 Replies

2. Shell Programming and Scripting

ksh view std err state

I would like to know if a command works. "command" 2>/dev/null When I issue the command, the error is suppressed. How can I tell whether there was an error? (3 Replies)
Discussion started by: robin_simple
3 Replies

3. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

4. Shell Programming and Scripting

password file as std input to script

I'm a fairly new AIX admin (disclaimer). We have SQL scripts written by end users that use a userid and passwd to connect to our DB2 database. Is it possible to create an "input file" that contains the db2 connect parameters and yet secure the file from the SQL creator? i.e., they can "use"... (2 Replies)
Discussion started by: mpheine
2 Replies

5. UNIX for Advanced & Expert Users

truss: script runs without, but 'sysntax err' with it ?!

When I run a script with truss it is exiting with error. Without truss the script runs fine! How to understand it? I have used the truss to resolve a 'magic' disappearing, but it brings own questions. The main problem is in a backgroun script, which on one server just disapeares,... (5 Replies)
Discussion started by: alex_5161
5 Replies

6. Shell Programming and Scripting

read from std i/p with timeout within a script

hello every one , this is my first participation in the forum , I hope it'll be a good start within a script I would like to put some code to read i\p from standard i\p using read command if it reads Y it will terminate the script if it reads N it will continue execution , if no i\p is... (2 Replies)
Discussion started by: Blue_shadow
2 Replies

7. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

8. Shell Programming and Scripting

How to redirect std err and out to log file for multi-commands?

The following command does not work under cygwin bash. ant debug >log 2>&1 && ant image >>log 2>>&1 & pid=$! It gives the error "-bash: sysntax error near unexpected token '&'". Is there a way I can redirect std output and std error to file "log" for both the commands "ant debug" and "ant... (1 Reply)
Discussion started by: siegfried
1 Replies

9. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question