Operating System - Linux
1819771 Members
3348 Online
109606 Solutions
New Discussion юеВ

Re: zip files need to be unzipped through cron

 
SOLVED
Go to solution
Abhijit P.
Valued Contributor

zip files need to be unzipped through cron

Dear all,

I am using a Red Hat Linux Server in which I am getting soem files from the remote locations through ftp in zipped format. Now the files which I am getiing goes in diff directories. I want to unzip these files through cron so that Manually i don't need to browse through each directory and unzip it.
The problem is when I run unzip * command it doesn't run I have to manually unzip one by one file. So I can't put it in cron.

Please help me out to solve this ..

Thanks and regards,
Abhijit

8 REPLIES 8
Gopi Sekar
Honored Contributor

Re: zip files need to be unzipped through cron


I believe you are simply putting 'unzip *' in your crontab, it will not work since cron does not understand the current directory. you may have to put it like 'unzip /path/to/zip/folder/*.zip'

Never Never Never Giveup
Gopi Sekar
Honored Contributor

Re: zip files need to be unzipped through cron

forgot to ask you, what is your crontab entry look like? because cron also supports wild cards and i am not sure whether this is affecting you.

Gopi
Never Never Never Giveup
renarios
Trusted Contributor

Re: zip files need to be unzipped through cron

Hi Abhijit,

Try this:
#!/bin/sh
# Search through a directory and unzip all files
DIR="dir_to_search"

find ${DIR} -name '*.zip" -exec gunzip {} \;

To extract the files use -d option.

Cheers,

Renarios
Nothing is more successfull as failure
renarios
Trusted Contributor
Solution

Re: zip files need to be unzipped through cron

Sorry, made a mistype:

#!/usr/bin/sh
# Search through a directory and unzip all files
DIR="dir_to_search"

find ${DIR} -name '*.zip' -exec gunzip {} \;

#EOT

Save this file as /root/gunzipper.sh

Put an entry in the crontab like:

# minute hour monthday month weekday command
0 0 * * * /root/gunzipper.sh
Nothing is more successfull as failure
Steven E. Protter
Exalted Contributor

Re: zip files need to be unzipped through cron

Remember, cron jobs have no environment.

If you want your job to be able to run unzip or zip without the full path, set the PATH variable before running any commands.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ivan Ferreira
Honored Contributor

Re: zip files need to be unzipped through cron

The find solution is good, but I think that gzip cannot decompress .zip files. You should use the unzip command.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Abhijit P.
Valued Contributor

Re: zip files need to be unzipped through cron

Dear Renarios,

Thanks for the script it worked

thank you very much
Regards,
Abhijit
Abhijit P.
Valued Contributor

Re: zip files need to be unzipped through cron

found solution to the problem
thanks