Solaris Script and Cron

Hi,

1. Is there any books or web sites you can recommend me on how to write Unix script (basic)?
2. Right now, i need to write a script to cp two huge files from one directory to another directory and zip, how to begin?

cd  /abc/backup
mkdir <date of creation>
cd <date of creation>
cp -p /efg/a50_5/log/pc* .
cp -p /efg/a50_5/log/sc* .
gzip *

 
Thanks in advance.

terrywongAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
yuzhConnect With a Mentor Commented:
1. For learning shell scripting, have a look at the following pages:

http://steve-parker.org/sh/sh.shtml
http://www.codebox.8m.com/shellscripting.htm

2. A example script for your question:

#!/bin/sh
TODAY=`date +%Y%m%d` # format 20030310
cd  /abc/backup
mkdir $TODAY
cp -p /efg/a50_5/log/pc* .
cp -p /efg/a50_5/log/sc* .
gzip *
exit

# End of Script

Cheers!





0
 
yuzhCommented:
If you are running an older version of Solaris (7 or older), you need to put the full path for gzip in the script.

eg:

/usr/local/bin/gzip *
0
 
elf_binCommented:
I do it like this:
#!/bin/sh

DAY=`date +%a-%d-%m-%y` # Can change format (see man date)

cd /abc/backup
mkdir $DAY
cd $DAY
cp -p /efg/a50_5/log/pc* .
cp -p /efg/a50_5/log/sc* .
/usr/bin/gzip *

The `` are escape characters that make the command run & the output of that is assigned to the variable DAY (we don't export the variable day, since we don't need it in any other script).

Hope this helps.

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
tfewsterCommented:
To save temporary space & time, try this instead of "cp then gzip" in your script.

for file in `ls efg/a50_5/log/pc*`
do
  gzip -c $file > `basename $file`.gz
done

The syntax may need to be different, depending on your shell.
0
 
NetminderCommented:
terrywong,

It's time to clean up this topic area. Please respond to the Experts' comments.

EXPERTS: Apparently, the Asker has abandoned this question. Please leave your thoughts on the resolution of this question here.

Netminder
EE Admin
0
 
tfewsterCommented:
Answered by yuzh
0
 
NetminderCommented:
Force-accepted.

Netminder
EE Admin
0
All Courses

From novice to tech pro — start learning today.