Outputting Errors to a Log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Outputting Errors to a Log file
# 1  
Old 02-14-2018
Outputting Errors to a Log file

Good Morning,

Every so often, I have copy scripts that to don't complete, but I don't immediately know why. It usually ends up being a permissions issue or a length issue.

The scripts edit a log file, so I'd like to include any copy errors/issues in that file to check if the copies ran into issues. I'm thinking:
Code:
cp -R /dir/dir/dir /dir2/dir2/dir2 2>&1 | printf /dir/dir/logfile

Will this work and/or is there something better? Will it work even if the script fails to complete the copy?
# 2  
Old 02-14-2018
printf does not open and print a file you want cat

Code:
cp -R /dir/dir/dir /dir2/dir2/dir2 2>&1 || cat /dir/dir/logfile

This only displays logfile when there is an error, which I guess is what you want. Note the double pipe.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 02-14-2018
Just as a FWIW. Copying files like that appears to be some kind of a backup attempt.
Not a great idea.

This may not be what you think it is. So. One thing I would consider seriously - simply for saving disk space and short term only- backup to a compressed tarball and possibly on another physically separate disk. For data security improvement.

e.g., tar cfz /path/tar_$(date '+%Y%m%d).tgz /dir/dir/dir
linux tar example

Move the tarballs offsite on storage media like tape after a week (or month) if they are truly important. Scheduling this is a business/legal decision....
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 02-14-2018
Quote:
Originally Posted by jim mcnamara
printf does not open and print a file you want cat

Code:
cp -R /dir/dir/dir /dir2/dir2/dir2 2>&1 || cat /dir/dir/logfile

This only displays logfile when there is an error, which I guess is what you want. Note the double pipe.
Thanks. Just to be clear, I don't want to display the log file. I want the existing log file (text document) to record any errors that happened during copying. Does this do that? Also, why the double pipe? This means do the second command if the first failed- correct? What are the two commands?
# 5  
Old 02-14-2018
cp doesn't write to stdout unless told so by e.g. the -v option. All error messages go to stderr. Try
Code:
cp -R /dir/dir/dir /dir2/dir2/dir2 2>/dir/dir/logfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting data from log file to report

I have a log file that looks like this. the lines are grouped. 2 lines per entry. M: 2019-01-25 13:02:31.698 P25, received network transmission from KI4EKI to TG 10282 M: 2019-01-25 13:02:35.694 P25, network end of transmission, 4.3 seconds, 1% packet loss M: 2019-01-25 13:02:38.893 P25,... (7 Replies)
Discussion started by: ae4ml
7 Replies

2. Shell Programming and Scripting

Scan log file for errors

Hi everyone. I am still new to UNIX, and am having trouble figuring out how to create a script to scan a log file to look for errors based on a string. We run AIX 5.3, and would like the ability to report all the instances of WebSphere Broker Execution groups crashing. This script would... (8 Replies)
Discussion started by: jimbojames
8 Replies

3. Shell Programming and Scripting

Finding errors in log file only in last 10 minutes

Hi there, I have a log file that I need to check every 10 minutes to find if a specific error exists but only in that 10 minute period. The reason is that the log is quite large, and will frequently contain these errors, so I only want alerting if it in the last 10 minutes - I don't want... (3 Replies)
Discussion started by: paul_vf
3 Replies

4. Shell Programming and Scripting

Capturing errors messages into log file

Can we capture and write all the error messages which were being displayed on the command prompt screen during execution of a program into a log file? If yes, can anyone please let me know on how to do it? I am using ksh and working on AIX server. Thank you in advance. (4 Replies)
Discussion started by: vpv0002
4 Replies

5. Shell Programming and Scripting

track the errors in log file

OS: SuSE Linux Enterprise Server 10 Goal: To track the errors in log file, If they exits users will be notify by email. We have a script below: SrchKey="SRVE0242I:" LogFile=/PATHtemOut.log MailTo="DN@mail.com http:// ! -f PATH/alert.last && touch PATH/alert.last egrep $SrchKey $LogFile... (3 Replies)
Discussion started by: sdhn1900
3 Replies

6. Shell Programming and Scripting

prevent errors/warnings from being written to log file

i have this script which works fine but shows errors when it runs..these are more like warnings and the script runs fine.. i am on a sun machine.. i know it writes all the error messages to a master log file.. is there any way i can turn off these warnings/error messages and prevent them from being... (2 Replies)
Discussion started by: npatwardhan
2 Replies

7. Shell Programming and Scripting

simple count script outputting mass errors

script outputting cant find anything wrong with the script either... : #!/bin/sh #count execution script time=0 while do if then time=`expr $time + 1` if then echo "The current tick is 100" fi fi (2 Replies)
Discussion started by: aspect_p
2 Replies

8. Shell Programming and Scripting

redirect errors to log file

I am working on a generic script that will run a shell script with the arguments passed and redirect errors to one file, and all other output to another file. Then if there is anything in the error file it emails the error to me, otherwise it exits. The advantage for this approach is that I... (0 Replies)
Discussion started by: gandolf989
0 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

Help in outputting the result in log files

This is the file am having: "40","1G1AL55 ",30482,9000 "40","1G1ZT58 ",29098,10600 "40","1G1AL15 ",29222,9400 "46","1G6KD57 ",3083,28400 "46","1G6KD57 ",27909,25200 "49","1G1ZU57 ",16391,13900 "49","1G2ZG58 ",28856,12400 I want to display the output in three files... (23 Replies)
Discussion started by: dave_nithis
23 Replies
Login or Register to Ask a Question