First off, there is no problem having a script longer than 60 lines - I routinely deal with shell scripts that have hundreds of lines in them, the shell doesn't care.
Without more information (show us your crontab entry/entries, and the whole script being run - how is this "$a
" populated? Does it contain spaces? etc.) it's hard to give you a good, definitive answer as to why this isn't working, but I can give you some food for thought:
I have an issue with the way you execute your scripts: Using timing to separate dependent actions is a recipe for disaster. Depending on how large these files are, how slow your disks are, whether you're crossing partitions, etc. etc. etc. it's possible your first script isn't finishing when your second script runs. This has two major implications:
Script 1
might still moving files over while Script 2
is making its tarball.
Script 2
is only tar
'ing the stuff it sees when it executes the tar
command.
Script 2
is also rm
'ing what it sees when it gets to the rm
command -- This could mean it's deleting stuff that wasn't added to the tarball
- If
Script 1
is still running you'll have "stray" files copied over after the rm
is done - These will just sit around.
@XoR's suggestion of chaining the scripts in cron is one way to protect yourself. So is combining both scripts into one larger script.
Using lock files (Linux has the lockfile(1) command ; I believe most of the BSDs have lockf(1)) is another option, and is somewhat more robust than chaining scripts together in cron.