Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie needs help

Status
Not open for further replies.

evild

Technical User
Nov 25, 2002
71
GB
I have a script that I need to decifer...

#!/bin/csh
set the_mon_day = `date '+%m-%d'`
set date_fields=`date`
set dayofweek = $date_fields[1]
cd /aleph/u52_5/ccc50/print/
cp * /aleph/u52_5/alephe/ccc/print
set the_dir = `find . -name "save*" -type d | grep $the_mon_day`
cd $the_dir
mv -f c_b_001.let* "/aleph/u52_5/ccc50/print/z_c_b_001.$dayofweek"
mv -f c_i_002.let* "/aleph/u52_5/ccc50/print/z_c_i_002.$dayofweek"
mv -f c_r_001.let* "/aleph/u52_5/ccc50/print/z_c_r_001.$dayofweek"
mv -f c_r_105.let* "/aleph/u52_5/ccc50/print/z_c_r_105.$dayofweek"
mv -f s_b_001.let* "/aleph/u52_5/ccc50/print/z_s_b_001.$dayofweek"
mv -f s_r_001.let* "/aleph/u52_5/ccc50/print/z_s_r_001.$dayofweek"
mv -f s_r_105.let* "/aleph/u52_5/ccc50/print/z_s_r_105.$dayofweek"
mv -f t_b_001.let* "/aleph/u52_5/ccc50/print/z_t_b_001.$dayofweek"
mv -f t_r_001.let* "/aleph/u52_5/ccc50/print/z_t_r_001.$dayofweek"
mv -f t_r_105.let* "/aleph/u52_5/ccc50/print/z_t_r_105.$dayofweek"
cd /aleph/u52_5/ccc50/print/
mv -f c_a_001.rpt "/aleph/u52_5/ccc50/print/z_c_a_001.$dayofweek"
mv -f c_b_201.rpt "/aleph/u52_5/ccc50/print/z_c_b_201.$dayofweek"
mv -f c_r_201.rpt "/aleph/u52_5/ccc50/print/z_c_r_201.$dayofweek"
mv -f s_r_201.rpt "/aleph/u52_5/ccc50/print/z_s_r_201.$dayofweek"
mv -f t_r_201.rpt "/aleph/u52_5/ccc50/print/z_t_r_201.$dayofweek"



I need help with some of these lines:
I would like to know what
set the_mon_day = `date '+%m-%d'` does
and what
set the_dir = `find . -name "save*" -type d | grep $the_mon_day`
does.

i understand that a value is set to the_mon_day and then used in setting the_dir. But what does all the other bits like +%m-%d mean?

The script renames files to a new name with a new prefix and a new suffix (the day of the week).

Thanks in advance.
 
Hi,
date '+%m-%d' this day gives value 05-07, tomorrow give 05-08 and so on.
find . -name "save*" -type d | grep $the_mon_day
find (beginning current directory) file whose name beginning
with save and containing 05-07 (for today) into the name and this file is directory.
Regards Boris.
 
Vars

Add echos to display the output to screen

set the_mon_day = `date '+%m-%d'`
echo $the_mon_day
set date_fields=`date`
echo $date_fields
set dayofweek = $date_fields[1]
echo $dayofweek

All that is happening is that variables are being setup

E.g

a=1
b=10
c=20

you can then say a+b+c = 31

expr $(($a+$b+$c))

use man date to see all optional flags for date

do
date +%m


the script then changes directory to aleph/u52_5/ccc50/print/

and copies (cp) all (*) to /aleph/u52_5/alephe/ccc/print

the_dir finds all directories in the current directory called save, I break that down a little more

set the_dir = `find . -name "save*" -type d | grep $the_mon_day`

find . = find in current dir, you could use find / or find /usr to specify another directory.
-name "save" the name of the thing you are searching for
-type d the type you are searching for.

do

man find

to see other options

the script then changes directory to the one found above

and moves (mv) files (-f) to "/aleph/u52_5/ccc50/print/ will adding the date onto the end of the filename






--
| Mike Nixon
| Unix Admin
|
----------------------------
 
what about these lines:

set date_fields = 'date'
set dayofweek = $date_fields[1]

What does $date_fields[1] mean?

since 'date' returns somethin like this:
Wed May 7 14:35:33 BST 2003

I assume that $date_fields[1] returns feilds 1 which would be 'Wed'?

Thanks for the replies so far :)
 
Arrays,like $date_fields[*] normally start at array[0], array[1], array[2] .... and so on, so by rights array $date_fields[1] would read May, Is this the bug you were looking for ?

L.
 
just one more question for clirification...

`find . -name "save*" -type d | grep $the_mon_day`


this looks for a directory (type d) that has the word 'save' in the name and contains the value the_mon_day?

Does the grep look for the_mon_day inside the directory that has 'save' in the name, or does it seach in the directory name?

 
Code:
grep
looks for
Code:
$the_mon_day
in lines printed by
Code:
find
which print the name of the directories whose name starts with
Code:
save
.

So the whole command looks for directories with
Code:
save
and
Code:
$the_mon_day
in their name.

This should do the same:
Code:
find . -name "save*$the_mon_day*" -type d
 
Change the first line to

#!/bin/csh -x

Then run the script.

It's a bit like filling up the script with lots of 'echo' commands :)

Or you could do it from the command line
csh -x myscript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top