LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2009, 02:40 AM   #1
kamil_maciejewski
LQ Newbie
 
Registered: Feb 2009
Posts: 1

Rep: Reputation: 0
(perl/bash) tar czvf|openssl enc and exit_code status


Well, I'm not experienced in BASH/PERL programming, sometimes I make some changes in the backup script. It compresses the data on a tape drive, check is everything done ok and sends a report via email. As it was earlier:

Code:
$exit_code=system("$tar czvf $tapedevice $oracle 1>$tar_status 2>$tar_errors");
and then
Code:
if ((stat($tar_errors))[7] && $exit_code)
checks wheater all is ok or not, click link to see all the code
Perl pastebin - collaborative debugging tool

Lately I added encryption for some more security
Code:
$exit_code=system("tar czvpf $tapedevice $oracle $samba $config $src $webdav | openssl enc -aes-256-cbc -salt -pass file:/tmp/.key 1>$tar_status2 2>$tar_errors2");
copy works, encryption too, but the report always says it's ok, even when it's not
Does anyone know how to check exit code so it would work with tar | openssl.

This is the full script (the part doing compression and encryption):
Perl pastebin - collaborative debugging tool
 
Old 02-20-2009, 06:25 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
If you're going to use system() that way, be aware that it returns the exit value of the system() cmd itself ie whether it ran ok or not. Nothing to do with the exit code(s) of the binaries you call in there.
What you would do is ensure you remove the error file before calling system() then stat the error file to see if it exists. If it does, you had an error, which you can get by reading the error file.

More sophisticated approaches inc using IPC::Open2.pm (http://perldoc.perl.org/IPC/Open2.html) or IPC::Open3.pm (http://perldoc.perl.org/IPC/Open3.html), or using Perl modules that deal direct with tar/ssl etc.
See search.cpan.org for modules.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar error - 'Child returned status 1' fabio_listas Linux - Newbie 8 01-16-2011 04:16 AM
Problem with tar piping through openssl to tape kaplan71 Linux - Software 2 11-23-2008 11:06 AM
Problems with openssl and perl jaakko_p Linux - Software 1 10-12-2008 07:42 PM
need some help with muli-volume tar (ubuntu, bash, gnu tar) MattCarp Linux - General 4 06-05-2006 08:15 AM
TAR Error Status 5 newbie1104 Linux - General 2 01-15-2006 06:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration