Bad Scripter

Bad Scripter

Post by Ingo Blechschmid » Fri, 31 Aug 2001 03:26:16






> > > I am trying to write script that will allow me to archive a directory by
> > > appending the current date in the following format (month.day.year).  The
> > > following code does this but I assume there has to be a more elegant
> > > solution:

> > > new_month=`date +%m`
> > > new_day=`date +%d`
> > > new_year=`date +%Y`
> > > mv testfile testfile.$new_month.$new_day.$new_year

> > > Is there an easy way to change the output of `date +%x` to use periods
> > > instead of slashes for delimeters?  I don't think I want to create files
> > > with multiple /'s in the name.

> > Don't kick yourself (too hard), but:
> >         mv testfile testfile.`date "+%m.%d.%Y"`
> > should do the trick.  Or:
> >         mv testfile testfile.$(date "+%m.%d.%Y")
> > which is a little bit nicer.

> Better still
>         mv testfile testfile.$(date "+%Y.%m.%d")
> so that files will be listed chronologically.

> --
>     Chris F.A. Johnson                        http://cfaj.freeshell.org
>     ===================================================================
>     My code (if any) in this post is copyright 2001, Chris F.A. Johnson
>     and may be copied under the terms of the GNU General Public License

Still still better
         mv testfile !#:1.$(date "+%Y.%m.%d")
!#:1 is expanded to the first argument (conting starts at 0), e.g.
testfile.

bye,
           Ingo Blechschmidt.

--
                                                                  _ _

Time sharing - the use of many people by the computer.           \_v_/

 
 
 

Bad Scripter

Post by Ben.Altma » Fri, 31 Aug 2001 04:24:15






> > > > I am trying to write script that will allow me to archive a directory by
> > > > appending the current date in the following format (month.day.year).  The
> > > > following code does this but I assume there has to be a more elegant
> > > > solution:

> > > > new_month=`date +%m`
> > > > new_day=`date +%d`
> > > > new_year=`date +%Y`
> > > > mv testfile testfile.$new_month.$new_day.$new_year

> > > > Is there an easy way to change the output of `date +%x` to use periods
> > > > instead of slashes for delimeters?  I don't think I want to create files
> > > > with multiple /'s in the name.

> > > Don't kick yourself (too hard), but:
> > >         mv testfile testfile.`date "+%m.%d.%Y"`
> > > should do the trick.  Or:
> > >         mv testfile testfile.$(date "+%m.%d.%Y")
> > > which is a little bit nicer.

> > Better still
> >         mv testfile testfile.$(date "+%Y.%m.%d")

> Still still better
>          mv testfile !#:1.$(date "+%Y.%m.%d")
> !#:1 is expanded to the first argument (conting starts at 0), e.g.
> testfile.

That's better still?  It has the advantage of lacking clarity and using csh which
should generally be avoided.
regards,
Ben Altman

--
P.S. the "From" address above should read benjamin.altman at noaa.gov.

 
 
 

1. Bad Scripter Part 2

Here is a script I wrote to archive a directory containing old code and to
create a new directory with the new code.  The script changes permissions
and also compiles the new code.  The first line kills the process so the
upgrade can be completed.  My question is, should I set a wait interval
after the first line to make sure the process is indeed dead, or should I
set a conditional statement that checks ps -ef for the process and will not
proceed until the process is dead.

Here is the line I use to kill the script:

kill `ps -ef | grep Coll | grep -v grep | awk '{print $2}'`

Thanks for any advice

fred (bad scripter)

2. samba

3. Bad Scripter

4. The real reason why MSWindows will NEVER be secure

5. 014 Bad Bad Bad !!! for Linux

6. ACL help (setfacl/getfacl)

7. Bad, bad, bad VM behaviour in 2.4.10

8. mod_rewrite: passing arguments as well.

9. Bad driver...Bad bad driver

10. Bad, bad, bad error...

11. SoftwarBuyLine.com is bad, bad, bad...

12. WANTED: Experienced Shell Scripters

13. new scripter needs help...