Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting Question 1

Status
Not open for further replies.

Tobinsk

Technical User
Jun 18, 2001
12
US
Hi,

I'm relatively new to Unix, and I've just written my first Unix script, which should basically write the start time of a cpio backup out to a log file, initiate the backup, and then write the finish time and the tape xstatus statistics out to the same log file.

However, it doesn't seem to work. The problem seems to be that none of the code in the script will execute after the cpio command. If I comment out the cpio command and run the script, it writes all the information out to the log file. I tried replacing the cpio command with simple commands, such as mkdir, just to test if the problem was specific to cpio, but the problem seems to occur regardless of what commands I use.

As I said, this is my first unix script, so I'm fairly sure the problem is something really small and obvious. Has anybody any idea what I might be overlooking? I'm using the Bourne shell for the script.

 
Could you send a copy of the script? SOL
The best thing about banging your head against a wall is when you stop.
 
Hi,

Here's the script. Basically, even if I remove everything after the cpio line, and put in a simple command like "echo complete", I get nothing. Probably something really stupid missing - I wrote this using only a few web-based scripting tutorials for reference.

#!/bin/sh
#This is a test script

backup_start="`date`"
echo Backup commenced $backup_start >bktest.txt

cd /snl/users/tobins
find . -follow -print | cpio -ocvBL -O /dev/rStp0

# Check exit status, and report
if [ "$?" -ne 0 ]
then
echo Exit Status $? >>bktest.txt
echo Backup process encountered errors and may not have completed successfully >>bktest.txt
echo Please verify. >>bktest.txt


else
echo Exit Status $? >>bktest.txt
echo Backup process completed successfully >>bktest.txt
fi
echo

backup_finish="`date`"
echo Backup completed $backup_finish >>bktest.txt

echo Tape Status Statistics: >>bktest.txt
tape xstatus >>bktest.txt

Thanks!
 
This is a simple problem - one often found with this type of script.

The find or cpio statement has hit a "pipe" file or a "FIFO" file. When this happens, the command hangs because a pipe or FIFO file in a sense never closes. Kind of like when you do a "tail -f".

For example, do a "cat /dev/zero". It is just going to hang.

Hope this helps. Bill.
 
*nice* catch Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
But you haven't helped [tt]tobinsk[/tt]!

Hey man try changing your [tt]find[/tt] command to:
[tt]
find . \( -type f -o -type d \) -follow -print
[/tt]

I hope it works...
Unix was made by and for smart people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top