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.
ProgrammingShell Scripting

Avatar of undefined
Last Comment
angireddy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
omarfarid

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
omarfarid

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.

angireddy

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
Tintin

With F-Secure SSH client, I think you have to use ssh2 instead of ssh.
angireddy

ASKER
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??
Tintin

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
angireddy

ASKER
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
Tintin

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

angireddy

ASKER
now i get  "gzip not found -- a  /usr/contrib/bin/gzip  224 blocks "
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Tintin

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

angireddy

ASKER
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.
angireddy

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
omarfarid

to delete the zipped file on the remote system:

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

Tintin

>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.
angireddy

ASKER
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
omarfarid

I think you need to put the full path to the command.

You may find the location of this file with

dir /s gunzip*.*
angireddy

ASKER
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?

Tintin

Try forward slashes, ie:

gunzip -q H:/SDP/dgaa01d/PRO\IN/globsvcddgaa01d*.gz
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
angireddy

ASKER
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???

angireddy

ASKER
i get error 9009
omarfarid

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
omarfarid

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
angireddy

ASKER

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.