1753946 Members
7481 Online
108811 Solutions
New Discussion юеВ

Re: Scripting Help

 
Sean Kuruvilla
Advisor

Scripting Help

Hello,

I am new to this scripting world. I was wondering if anyone had a script that would find a certian file in my HPUX 11.0.b server then either email it or FTP it out to a certian address. It really help me out. Thank you in advance.
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Scripting Help

Hi:

There are plenty of threads in this Forum for simple FTP scripts. Simply search for those. One variation is:

#!/usr/bin/sh
ftp -n << EOF
open thehost
user uuu ppp
get /tmp/stuff
close
EOF

...Substitute the appropriate hostname for "thehost". Substitute the appropriate user login and password for the "uuu" and "ppp" strings, respectively, and do a 'get' or 'put' of the file you want, accordingly.

As for finding a file, 'find' is your friend. For example, to find a file containing the characters 'sean' in the directory '/var' you could do:

# find /var -xdev -type f -name "*sean*"

The '-xdev' argument prevents 'find' from crossing mountpoints in its search through the 'var' directory and subdirectories. The '-type f' says look only for *files*, not directories and sockets and pipes. The enclosure of the string "*sean*" in quotes keeps the shell from expanding the wildcard characters and let's 'find' look for any file basename that contains the string "sean" somewhere. Thus, the 'find' would find "sean", "seansfile", "the_sean_file", etc.

Regards!

...JRF...
Peter Godron
Honored Contributor

Re: Scripting Help

Sean,
if you know there is only one file by that name:
cat `find / -name filename` | mailx -s"Found" email@aol.com

where you replace filename with the filename you are looking for and email@aol.com with your email address.

Re: Scripting Help

and another example of how you could email as attachement if file is unique... mime type could be changed depending on the type of file. Make the body and subject whatever...

find /path -type f -name yourfile -print |xargs mailfile.sh

Hope this helps,
-denver
spex
Honored Contributor

Re: Scripting Help

Hi Sean,

Multiple files matching your search pattern are okay, too:

#!/usr/bin/sh
find /abs_path -type f -name '*query*' -print | xargs tar cvf /tmp/query.${$}.tar
uuencode /tmp/query.${$}.tar query.tar | mailx -m -s "[$(date +%m\/%d\/%y)] query.tar attached" your@email.addr
rm -f /tmp/query.${$}.tar
exit

PCS

Martin Roende
Advisor

Re: Scripting Help

Dont forget , what is mentioned as last entry in this itrc entry, (about scripting in cron )
If thats where you are going to use it ...

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1061204&admit=-682735245+1158777821599+28353475

regards martin at unixera dk