Handling tape errors in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Handling tape errors in script
# 1  
Old 03-07-2013
Handling tape errors in script

AIX 7.1
Here's the script
Code:
#!/bin/ksh
find . -print > filelist.txt
backup -ivqf/dev/rmt0 < filelist.txt > backup.log
if [ "$?" != "0" ]; then
    echo "Backup to tape failed!" >> backup.log
else
   echo "Backup to tape successfull!" >> backup.log
fi
mail -v -s "Backup report" maillist < backup.log

I'd run this from cron.
But for now, while I'm testing the first time I ran it I got this message on the console:
Code:
backup: 0511-089 Cannot open /dev/rmt0: The input or output media is write-protected.
Mount volume 1 on /dev/rmt0.
        Press Enter to continue.

If I had such an error running from cron, no one would see it.
How can I handle this situation?

Thanks,
-dog
# 2  
Old 03-07-2013
It is likely being printed to standard error, file descriptor 2. You are capturing stdout only, FD 1, but you can capture both (preferably to separate logfiles).

You can simplify the script by redirecting stdout of the script itself, instead of reopening the same file 5 times. Also, there's no reason to use $? here, you can plug the command directly into the if statement.

Code:
#!/bin/ksh
exec >backup.log # Open once instead of 5 times
exec 2>backup.err # All stderr lines will end up here.

find . -print > filelist.txt

if backup -ivqf/dev/rmt0 < filelist.txt
then
   echo "Backup to tape successfull!"
else
    echo "Backup to tape failed!"
fi
cat backup.log backup.err | mail -v -s "Backup report" maillist

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-07-2013
Thanks!

What if the stderr message is this:
Code:
backup: 0511-089 Cannot open /dev/rmt0: The input or output media is write-protected.
Mount volume 1 on /dev/rmt0.
        Press Enter to continue

Would it just hang as no one could "Press Enter" ?
# 4  
Old 03-07-2013
Yes, it would probably just hang. I guess you would get an error message sent to your email from cron. If not, you could have the script create a "success" file. Then, later in the evening, have cron run script #2 to see if "success" file is there. If not, script #2 sends you an email. When you get email, you un-write-protect the tape, or whatever other action needed.

Hope this helps.
# 5  
Old 03-08-2013
Quote:
Originally Posted by landog
Thanks!

What if the stderr message is this:
Code:
backup: 0511-089 Cannot open /dev/rmt0: The input or output media is write-protected.
Mount volume 1 on /dev/rmt0.
        Press Enter to continue

Would it just hang as no one could "Press Enter" ?
When your script is run from cron, it has nothing to read ENTER from -- no terminal. When the utility tries to read, it will get EOF or some sort of error, and probably quit. A badly-coded program might go into an infinite loop though.

A well-coded program could even tell that it has no terminal, and not bother trying.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script handling processes

Hello I have a file which has around 120 lines of commands. I am trying to write a shell script like which reads the 'command' file and executes line by line with some additional (common argument) with maximum 6 commands active at a time. Each of these commands when executed takes time... (5 Replies)
Discussion started by: JackyShane_36
5 Replies

2. Shell Programming and Scripting

Expect Script Error Handling

Good Day Everyone, I was hoping to get a little insight into an expect script that I've written. Basically we have this expect script to perform an sftp upload, key authentication is not an option, and sftp is the only method supported by our vendor, thus the need for this. I want to be... (3 Replies)
Discussion started by: thaller
3 Replies

3. Shell Programming and Scripting

Help with Error Handling on Script

Hi, I need your guys help again. I run a script which check for some process status in a loop. when i check the process some of the process could throw an error, how can i check that inside my script. Thanks, RR (3 Replies)
Discussion started by: rrb2009
3 Replies

4. Shell Programming and Scripting

File handling in Script

Hi All, How can we handle file operation in scripts. I have written a script that run ok otherwise however the "Cat" operation leaves a process open on the box. Command is like cat "${LASTFILENAME}" | /usr/xpg4/bin/awk -F, '{do{if ($3 == "100" && $4 == "300" && $170 ~ /^abc/) { ... (2 Replies)
Discussion started by: raman1605
2 Replies

5. UNIX for Dummies Questions & Answers

Handling input from a ls in a script

I'm trying to write a script that will handle the input from the ls command in my script so I can then manipulate the data. For example, I want to capture the output of the ls command in my script and then do a differences between the filename received in to another directory. ls |... (1 Reply)
Discussion started by: spookyrtd99
1 Replies

6. Shell Programming and Scripting

handling filespec in bash script

hi there, i just need a help handling the output of filespec in case has been picked im writing a bash script similar to the command ls, and ive done everything except handing the filespec which i spent more than 3 hrs and i coundn't figure out or find any on the net. all what i need is... (11 Replies)
Discussion started by: new2Linux
11 Replies

7. SCO

Tape Status shows 2 Hard errors and 5 Underruns on new tape

when I do a tape status /dev/rStp0 I get the following on a new tape and I have tried several: Status : ready beginning-of-tape soft errors : 0 hard errors: 2 underruns: 5 My BackupEdge has stopped backing up my system because it asks for a new volume yet my total system data is under 20... (5 Replies)
Discussion started by: psytropic
5 Replies

8. Shell Programming and Scripting

Shell script file handling

Hi ! /bin/sh set logdir1 "logDir/local/logname" #write the filename into a file echo $logdir1 >> logname.txt how do i exec the above echo command (1 Reply)
Discussion started by: nathgopi214
1 Replies

9. UNIX for Dummies Questions & Answers

Handling Errors in Shell Scripts

I have a shell script, which calls a load script to load a database. How can i handle errors in Unix(similar to 'error level' in Batch scripts)? I am trying to use 'mailx' to send a Success/failure message based on the error level returned by the load script. I have already used an error log... (2 Replies)
Discussion started by: sarsani
2 Replies

10. UNIX for Dummies Questions & Answers

SCO 5.0.5 Tape Drive errors

hi guys, I.m trying to remove and add a new tape drive by using the mkdev tape command and when i try to update the Kernel this is what i'm getting, i386ld: Symbol Sdsk_no_tag in /var/opt/K/SCO/link/1.1.1Eb/etc/conf/pack.d/blad/s pace.o is multiply defined. First defined in... (0 Replies)
Discussion started by: josramon
0 Replies
Login or Register to Ask a Question