0

I am trying to extract files from a tape device using tar and am getting IO errors:

tar: /dev/nst0: Cannot read: Input/output error

However, tar tries to continue anyway:

tar: Skipping to next header

Is there a way to tell tar to exit directly after the first occurrence of the Cannot read error? I worked my way through the man pages and the tar manual, but could not find anything like that. Or is there a way to catch the error message in the calling shell and kill tar from outside?

The OS is Ubuntu 16.04 with kernel 4.4.0-38 and tar is GNU tar 1.28.

2
  • Which OS and which tar implementation are you using? Commented Nov 26, 2016 at 21:32
  • The OS is Ubuntu 16.04 with kernel 4.4.0-38 and tar is GNU tar 1.28.
    – allion
    Commented Nov 26, 2016 at 22:20

1 Answer 1

0

You could use an expect script:

#!/usr/bin/expect -f

# Timeout: 10000 seconds
set timeout 10000

spawn tar your tar args come here
# spawn custom-tar-script.sh

expect "tar: /dev/nst0: Cannot read: Input/output error"

send_user "Will kill PID <[exp_pid]>.\n"
exec kill [exp_pid]
# exec killall tar
# exec custom-kill-script.sh
close

(Adapt it to your needs)

2
  • Thanks, looks like this does the "killing from outside" that I had in mind. When the timeout is over does it terminate the spawned script?
    – allion
    Commented Nov 29, 2016 at 17:14
  • Yes, for that reason I increased the timeout (~10 seconds is default).
    – u_Ltd.
    Commented Nov 29, 2016 at 21:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .