Link to home
Create AccountLog in
Avatar of angireddy
angireddy

asked on

Shell Script to zip files

How do i zip a file using shell script ...currently i use this script to copy the files


scp2 -c blowfish haca01a@ipaddress:/gis/ghr/acc/gshared/hrglobalvals/OUT/* H:\SDP\dgaa01d\PRO\IN\GHRDB


how can i modify that to zip the files when copying from the srver.
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of angireddy
angireddy

ASKER

I need to zip them into a Microsoft windows server 2003 system.. i am getting an error  ssh is not recognised  as an internal or external command
What ssh S/W are you using on your system? What OS are you running?

Is the remote system is a unix system and what flavor?

I sow that you are using scp2, what S/W it is part of?

If you are on a windows system then, you may use putty (plink) S/W.

I am using F-Secure SSh Client.. Windows 2003 server  operating system... Yes the remote system is a Unix system but not sure what flavour
With F-Secure SSH client, I think you have to use ssh2 instead of ssh.
i used ssh2 dgaa01d@hpux69d1 "/usr/contrib/bin/gzip /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_* > /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606.xml.gz"


and its supposed to create zipped version of the file in   /gis/gdf/dev/dgaa01d/workarea folder ...but it created a zip in gis/gdf/dev/dgaa01d/OUT/ folder also ...can anyone help me with this script??
I'd do it like


ssh2 ssh2 dgaa01d@hpux69d1 "zip /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.zip /usr/contrib/bin/gzip /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_*"

Open in new window

i dont under stand why u need to use zip in this first part... i get "zip not found"

zip /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.zip
You originally stated you wanted to zip the files, so I assumed that's what you wanted to do.  If you don't have zip installed on your Unix box, then you'll have to use tar and gzip, eg:


ssh2 ssh2 dgaa01d@hpux69d1 "tar cvf - /usr/contrib/bin/gzip /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_* | gzip -c > /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.tgz"

Open in new window

now i get  "gzip not found -- a  /usr/contrib/bin/gzip  224 blocks "
I'm sorry, I mis-copied the command, it should be:


ssh2 dgaa01d@hpux69d1 "tar cvf -  /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_* | /usr/contrib/bin/gzip -c > /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.tgz"

Open in new window

that helped .. also how would i delete the files after copying them over to my local dir...so my steps of execution are:

1)  Gzip the files from OUT folder to workarea
ssh2 dgaa01d@hpux69d1 "tar cvf -  /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_* | /usr/contrib/bin/gzip -c > /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.tgz"
 
2)  Copy files to my local folder from workarea
     scp2 -c blowfish dgaa01d@hpux69d1:/gis/gdf/dev/dgaa01d/workarea/* H:\SDP\dgaa01d\PRO\IN\

3)  Delete all files in workarea aftre copy is successfull.
Actually i need to add a step in between also...how do i unzip the files in my local folder before delting them

1)  Gzip the files from OUT folder to workarea
ssh2 dgaa01d@hpux69d1 "tar cvf -  /gis/gdf/dev/dgaa01d/OUT/businessdgaa01d_* | /usr/contrib/bin/gzip -c > /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.tgz"
 
2)  Copy files to my local folder from workarea
     scp2 -c blowfish dgaa01d@hpux69d1:/gis/gdf/dev/dgaa01d/workarea/* H:\SDP\dgaa01d\PRO\IN\

3) Unzip the files in my local folder

4)  Delete all files in workarea aftre copy is successfull.
to delete the zipped file on the remote system:

ssh2 dgaa01d@hpux69d1"/usr/bin/rm /gis/gdf/dev/dgaa01d/workarea/businessdgaa01d_20080411192606-xml.tgz"

>3) Unzip the files in my local folder

Do you have cygwin installed on your Windows server?  If not, you'll have to use Winzip or similar to extract the files.
I have Gzip installed...but dont know the commands on how to unzip it.used   this


gunzip -q H:\SDP\dgaa01d\PRO\IN\*.gz    but it says unrecognised command
I think you need to put the full path to the command.

You may find the location of this file with

dir /s gunzip*.*
I have a wierd issue now ..  

I have my .gz files under H:\SDP\dgaa01d\PRO\IN\

in command prompt it is C:\Documents and Settings\testuser

when i execute

C:\Documents and Settings\testuser>gunzip -q H:\SDP\dgaa01d\PRO\IN\globsvcddgaa01d*.gz

i get issue "H:\SDP\dgaa01d\PRO\IN\globsvcddgaa01d*.gz no such file or driectory"

how do i get the gunzip to unzip files in that path whithout changing the directory?

Try forward slashes, ie:

gunzip -q H:/SDP/dgaa01d/PRO\IN/globsvcddgaa01d*.gz
ok  this command works when i run it locally on my server

gunzip -q D:\XMLDATA\GFIS\*.gz

but when i run it remotely meaning if this job is scheduled thru a remote server...it failes...the other jobs like downloading works..

scp2 -c blowfish dgaa01p@ipaddrss:/gis/gdf/pro/dgaa01p/workarea/* D:\XMLDATA\GFIS\


what is the difference with the unzip job when it runs remotely and runs locally???

i get error 9009
When you run the unzip remotely, then it is run on the remote system on the remote files. When you run it locally, you run it on local system on local files. If you run it remotely then you transfer unzipped files.
If you do not have an unzip tool on the local system, then you may unzip the files on the remote system and copy them with scp. if you have a dir with subdir you may use the -r option with scp

I have these scripts in a DTS package and this DTS package is run by a scheduling job called CTRL M.
When i run the DTS manually it run fine but when it is run by CTRL M(remote scheduling process) it fails.
These 2 lines exist in the in a .bat file and i call this .bat file from DTS package.

This line runs fine when DTS is called by CTRL M
scp2 -c blowfish dgaa01p@ipaddrss:/gis/gdf/pro/dgaa01p/workarea/* D:\XMLDATA\GFIS\

This line fails when DTS is called by CTRL M
gunzip -q D:\XMLDATA\GFIS\*.gz

but works fine when the DTS is run manually.