Michael Leone on 13 Mar 2012 07:48:15 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] Need some script advice

Note that I am not a Linux scripting guy by ANY stretch of the
imagination. But I do have a simple script that I could use some
advice on.

I have a script that we use to transfer FTPed invoices from a machine
on our DMZ to the trusted LAN. This script reaches out to the DMZ and
runs a script that that ZIPs up all invoices it finds. Then my script
RSYNCs it from the DMZ to the trusted LAN. This all works.

Next, my script extracts out from the zip all the individual files,
and moves them to a special folder. Then it makes a copy of the zip
file in an archive folder. Then it deletes the zip from the working
directory (since we safely have it in the archive).

Well, somehow the script hiccupped the other day, and did NOT copy the
zip from the working directory to the archive before deleting it. (no,
I don't know why yet - possibly a credentials problem, the interactive
run may not have been done by the right account. That's a separate

What I need to do: verify that the script exists in the archive BEFORE
deleting. If it doesn't exist, I want it to email me.

I know I can do (thank you Google, for the example):

if [ -f zip-file-name]
     echo 'Adding to archive'
     cp *.zip /Archive
     mailx -s "All good!" ...
     echo 'File not found!'
     mailx -s "Problem making archive! Come look" .....

Here's what I don't know how to do - determine that zip-file-name, so
I can check it. There will only ever be 1 zip file in the working
directory. How do I capture that name, to then feed it into the code
snippet above. I guess what I am asking:

how can I save the name of the single file that is in this directory
to a variable? (I will then use that variable in the test above)

I'm sure it's simple, I just don't know how ...

Mike Leone, <mailto:turgon@mike-leone.com>

Angels and demons dancing in my head
Lunatics and monsters underneath my bed
Media messiahs preying on my fears
Pop culture prophets playing in my ears
                      Rush, "Totem"
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug