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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find files, tar and send to user

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello All,

I am trying to create a unix script in SOLARIS that will do the following:
1) find all file in this directory that has non-zero size.
2) the result from 1) should be newer than file_z
3) tar the resulting files from 2) into a tarball
4) send the resulting tarball from 3) to a recipient

Here is my effort that does not work. Please advise on what I am doing wrong.

#!/bin/sh

find . -type f ! -size 0 | find . -type f –newer file_z –print
tar -cvzf mysendfiles.tar.gz * | mail -s ‘file counts’george.goldenberg@ezee.com
 
There are a few problems.

You can't pipe find into find ("|" is not used for "or" logic, it means the output of the first find is piped into the standard input of the second one.

There's no point in generating a file listing if you are just going to put a "*" on the tar command line... it will just archive all files that match "*".

Piping the the output of tar into mail will just make it include the list of files added to the archive, not the archive itself.

Try this (untested) version:

Code:
find . -type f ! -size +0 –newer file_z –print | tar -cvzTf - mysendfiles.tar.gz
uuencode mysendfiles.tar.gz mysendfiles.tar.gz | mail -s 'file counts' george.goldenberg@ezee.com

The tar -T - option tells it to read the list of files to add to the archive from standard input. uuencode converts the archive into a format that will be understood by an email reader.

Annihilannic.
 
Actually, just realised you are doing this on Solaris. tar on Solaris does not support -z to automatically gzip the archive. Also it uses a different option for include files (-I instead of -T so try this modification of the first command:

Code:
find . -type f ! -size +0 –newer file_z –print | tar -cvIf - | gzip -c > mysendfiles.tar.gz

Annihilannic.
 
Hello,

I am new to scripting on Solaris. I need to create and run a shell script that will take some input and then perform the commands in the shell script, for example:

#./shellscript.sh input

contents of the script:

rcp -p input user@host1:input
rsh -l user host1 "chmod 755 input"

So its quite basic, but not sure how get input into the script, and not sure about the structure either.

Any help would be greatly appreciated!

Cheers!
 
my bad, posted as a reply! Admin please delete above reply! (and this one!)
 
Just Red Flag your own post with an explanation and the admins will delete it.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top