Yahoo : Winternet : TC Guide  : Files of Local Interest Enter Sysinfo.com :



Subject: Re: Global copy/rename
Subject: Re: Quick Command For Parsing Filename
Subject: Re: Quick Command For Parsing Filename
Subject: Re: Scripting question: validation of command line arguments
Subject: Re: Scripting question: validation of command line arguments
Subject: Re: Edit $PATH ?
Subject: Re: filenames
Subject: Re: CRONTAB and environment--please help
Subject: Re: Scripting help needed.
Subject: Re: Scripting help needed.
Subject: Re: Scripting help needed.
Subject: Re: Shell script advice please




From: Per Erik Jorde <ejorde@biomar16.uio.no>
Newsgroups: comp.unix.questions
Subject: Re: Global copy/rename
Date: 09 Mar 1999 14:25:07 +0100
Lines: 23

mswee@hcia.com writes:

>=20
> I am attempting to copy or rename a large number of files on a Unix sys=
tem.  I
> am familiar with doing this in DOS, with the following statement:
>=20
>    COPY *.ABC *.XYZ or RENAME *.ABC *.XYZ
>=20
> Unfortunately, Unix doesn't allow for this.  I have attempted to do thi=
s using
> a shell script (bourne shell) with a "for file in *.ABC" statement, but=
 I am
> unable to determine a method which to drop the ".ABC" extension from th=
e $file
> variable.

Use =ABbasename=BB to drop the extension:

for oldname in *.ABC ;
  do newname=3D`basename $oldname .ABC` ;
  mv $oldname $newname.XYZ ;=20
done

pej
--=20
Per Erik Jorde

--=20


From: brian hiles <bsh@rainey.blueneptune.com>
Newsgroups: comp.unix.questions,comp.unix.shell
Subject: Re: Quick Command For Parsing Filename
Date: 9 Mar 1999 01:10:57 GMT
Lines: 36
User-Agent: tin/pre-1.4-980226 (UNIX) (FreeBSD/2.2.6-RELEASE (i386))

In comp.unix.shell Tony George <tgeorge@cae.ca> wrote:
> I'm trying to come up with some simple 'cut', 'awk', or 'sed'
> ...
> 1. SAR_19990304102310
> 2. cws2_19990304102310.422--00005.msg.yz.Z
> 3. cws2_l_19990304102310.422--00005.msg.yz.Z
> ...

Horrors! Sed? Awk? Expr? All of these are monster executables that
take 100 times longer just to _load_ than to use techniques for parsing
such strings built into even the most ancient of sh(1).

for filename in \
	SAR_19990304102310 \
	cws2_19990304102310.422--00005.msg.yz.Z \
	cws2_l_19990304102310.422--00005.msg.yz.Z
do	IFS=_.
	set -- $filename
	case $2 in
	19*)	timestamp=$2 ;;
	*)	timestamp=$3 ;;
	esac
	echo $timestamp
done

In a recent thread I had touched on the generalized technique of
parsing strings by the scripting idiom:

IFS=_. eval "set -- X \$filename; IFS='$IFS' shift"

In ksh the technique is not so problematic, but in sh(1) (which
uses IFS to do word spearation upon its own command line), the
above shows a technique to parse using IFS and change the value
back to the original _in one command_.

-Brian

-- 


From: cdu@jawa. (chris ulrich)
Newsgroups: comp.unix.questions,comp.unix.shell
Subject: Re: Quick Command For Parsing Filename
Date: 9 Mar 1999 09:33:05 GMT
Lines: 40

In article <36DEF564.66F6@cae.ca>, Tony George  <tgeorge@cae.ca> wrote:
##Hi,
##
##I'm trying to come up with some simple 'cut', 'awk', or 'sed'
##
##1. SAR_19990304102310
##2. cws2_19990304102310.422--00005.msg.yz.Z
##3. cws2_l_19990304102310.422--00005.msg.yz.Z
##
##What I'd like to do is have a command that would just
##extract the 14-digit timestamp after the "_" character,
##whether it be 1 underscore like in #1 and #2 or after
##2 underscores like in #3.
##
##e.g. echo filename | <something in here> --> 14-digit timestamp
##
##Any ideas would be much appreciated...
##
##
##                            Tony

  Eeek.  awk & sed are kind of big guns for this sort of thing.

I'd use something like:

echo $filename | while IFS=_. read a b c d e
do
  case $b in
    '')  echo "Huh?" ; exit 3 ;;
    ??????????????) echo $b ;;
    *) echo $c ;;
  esac
done

  I'll admit, it's no one-line-wonder, but it'll be faster than
sed or awk, plus just from looking at it you can kind of figure out
what's going on inside...  
chris
--
chris@tinker.ucr.edu          /         no forks found here

-- 


From: ken@halcyon.com (Ken Pizzini)
Newsgroups: comp.unix.questions
Subject: Re: Scripting question: validation of command line arguments
Date: 10 Mar 1999 21:35:04 GMT
Lines: 14
Reply-To: ken@halcyon.com
User-Agent: slrn/0.9.5.3 (UNIX)

On Wed, 10 Mar 1999 15:35:45 GMT, mswee@hcia.com <mswee@hcia.com> wrote:
>I've developed some bourne shell scripts to automate some tasks on my system.
>The scripts will accept a parameter, which should be an integer else the
>program will come up with some unexpected results.  I am unsure as to how I
>can validate that the command line arguments is an integer in the script. 
>Any hints?

if expr "$param" : "[0-9][0-9]*$" >/dev/null; then
  echo "$param okay"
else
  echo "$param bad"
fi

		--Ken Pizzini

-- 


From: Arvind Sharma <asharma@uswest.com>
Newsgroups: comp.unix.questions
Subject: Re: Scripting question: validation of command line arguments
Date: Wed, 10 Mar 1999 17:02:50 -0700
Lines: 54
Mime-Version: 1.0

This is a multi-part message in MIME format.
--------------D3A32DBD2BE5B23354204ED9

Check
echo $variable |grep [0-9]
if [ $? = 0 ]
then
   echo integer
else
    echo not an integer
fi

mswee@hcia.com wrote:

> I've developed some bourne shell scripts to automate some tasks on my system.
> The scripts will accept a parameter, which should be an integer else the
> program will come up with some unexpected results.  I am unsure as to how I
> can validate that the command line arguments is an integer in the script.
> Any hints?
>
> Thanks in advance,
>
> Michael
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own





-- 


From: ken@halcyon.com (Ken Pizzini)
Newsgroups: comp.unix.questions
Subject: Re: Edit $PATH ?
Date: 17 Mar 1999 22:17:32 GMT
Lines: 11
Reply-To: ken@halcyon.com
User-Agent: slrn/0.9.5.3 (UNIX)

On 17 Mar 1999 21:25:02 GMT,
VanPopering <dvanpope@bookworm.suffolk.lib.ny.us> wrote:
[Nothing.  Must have been implicitly echoing the subject "Edit $PATH ?"]

Here's an edit to remove a standard security hole:
  PATH=$(echo "$PATH" |
         sed 's/.*/:&:/; s-:\./*:-:-g; s/::*/:/g; s/^://; s/:$//')

Alter (or replace) the "sed" to suit...

		--Ken Pizzini

-- 


From: ken@halcyon.com (Ken Pizzini)
Newsgroups: comp.unix.questions
Subject: Re: filenames
Date: 26 Mar 1999 19:31:05 GMT
Lines: 19
Reply-To: ken@halcyon.com
User-Agent: slrn/0.9.5.3 (UNIX)

On Fri, 26 Mar 1999 12:30:22 -0400, Alex MacAskill <026759m-@-acadiau.ca> wrote:
>        anyone know how I could take a directory of files and rename
>them all
>to say like pic1.jpg pic2.jpg etc etc
>
>So it would start by naming the first one pic1.jpg the second file would
>be pic2 and so on.

If I understand you right, this is just:
  i=1
  for f in *; do
    mv "$f" pic$i.jpg
    (( i += 1 ))
  done


A good tutorial/book on shell programming would be useful here...

		--Ken Pizzini

-- 


From: Phil Cuff <philcuff@my-dejanews.com>
Newsgroups: comp.unix.questions
Subject: Re: CRONTAB and environment--please help
Date: Tue, 13 Apr 1999 21:36:25 GMT
Lines: 37

In article <7evr09$sr4$1@news2.cellnet.com>,
  epaik@cellnet.com (Ellen Paik) wrote:
> Can someone please help me with the following:
>
> For a certain entry in my crontab file, I need to propagate all my
> environment variables for it to run.  (path, hosttype, pwd, etc.)
> The manpage for crontab states that if you want this you need to
> have a line that executes your .profile in the crontab file, but
> how is this done?
>
> Any help would be much appreciated.
>
> Ellen Paik
>

If you're the sysadmin, you can put an entry something like the following in
root's contab:

  55 3 * * * su - logname -c commands

The "su - logname" will change the environment to what would be expected if
the user had actually logged in.  If you must use your own crontab, then...

  55 3 * * * . .profile; commands

Cron sets a default environment which includes setting the current working
directory to your home.  The ". .profile" tells the current shell to read
your profile.  If the command you want to run is a script, you could also
source your .profile from within the script in the same fashion.

Phil C.


Phil C.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

-- 


From: "ADS1 Weissmann.W" <weissman@aviehe70.atc.co.at>
Newsgroups: comp.unix.admin
Subject: Re: Scripting help needed.
Date: 16 Apr 1999 12:18:30 +0100
Lines: 20
User-Agent: tin/pre-1.4-981225 ("Volcane") (UNIX) (HP-UX/B.10.20 (9000/712))

Mattias Lundstrom <mattias.lundstrom@sebank.se> wrote:
> Hi
> I need some suggestions...

> I'm wtiting a simple script that will send a mail with an attachment to
> a certain user;

> #!/bin/ksh
> for i in `ls *.txt`
> do
> uuencode $i foo |mailx -s "File $i" root@localhost
> done

> How can I attach multiple *txt files to the mail?
tar cf - *.txt|uuencode -|mailx root@localhost

thats a one-liner!

chao
Wilfried

-- 


From: gburnore@databasix.com (Gary L. Burnore)
Newsgroups: comp.unix.admin
Subject: Re: Scripting help needed.
Date: Fri, 16 Apr 1999 11:59:19 GMT
Lines: 37
Reply-To: gburnore@databasix.com
Mime-Version: 1.0

On 16 Apr 1999 12:18:30 +0100, "ADS1 Weissmann.W"
<weissman@aviehe70.atc.co.at> wrote:

>Mattias Lundstrom <mattias.lundstrom@sebank.se> wrote:
>> Hi
>> I need some suggestions...
>
>> I'm wtiting a simple script that will send a mail with an attachment to
>> a certain user;
>
>> #!/bin/ksh
>> for i in `ls *.txt`
>> do
>> uuencode $i foo |mailx -s "File $i" root@localhost
>> done
>
>> How can I attach multiple *txt files to the mail?
>tar cf - *.txt|uuencode -|mailx root@localhost
>
>thats a one-liner!

It is, but some people can't read tar files.

And while the following isn't a one liner, it sends all the .txt files
in your current directory in one email message.

#!/bin/ksh

cp /dev/null /tmp/mailfile.$$
for i in *.txt
do
   uuencode $i $i >> /tmp/mailfile.$$
   echo "\n\n" >> /tmp/mailfile.$$
done

cat /tmp/mailfile.$$ | mailx root@localhost
rm /tmp/mailfile$$

-- 


From: "ADS1 Weissmann.W" <weissman@aviehe70.atc.co.at>
Newsgroups: comp.unix.admin
Subject: Re: Scripting help needed.
Date: 19 Apr 1999 19:24:45 +0100
Lines: 46
User-Agent: tin/pre-1.4-981225 ("Volcane") (UNIX) (HP-UX/B.10.20 (9000/712))

Mattias Lundstrom <mattias.lundstrom@sebank.se> wrote:
>> >tar cf - *.txt|uuencode -|mailx root@localhost
>> >
>> >thats a one-liner!
>>
>> It is, but some people can't read tar files.
>>
>> And while the following isn't a one liner, it sends all the .txt files
>> in your current directory in one email message.
>>
>> #!/bin/ksh
>>
>> cp /dev/null /tmp/mailfile.$$

Ugh! that hurts! ( you don't need this. and if you are doing something
similar then try: >file )

>> for i in *.txt
>> do
>>    uuencode $i $i >> /tmp/mailfile.$$
>>    echo "\n\n" >> /tmp/mailfile.$$
>> done
>>
>> cat /tmp/mailfile.$$ | mailx root@localhost
>> rm /tmp/mailfile$$

> Nice, but the files have to be sent as attachments.

#!/bin/ksh
(  cat "$1"
for file in *.txt
do
  uuencode "$file" "$file"
done ) | mailx root@localhost

The first parameter is the file which contains the message.
You could also do something that calls an editor and stuff to get some
nice look and feel.
But I leave this up to you.

> regards,
> Mattias

chao
Wilfried


-- 


From: Reg Smith <rjsmith@uk.oracle.com>
Newsgroups: comp.unix.questions
Subject: Re: Shell script advice please
Date: Fri, 09 Apr 1999 17:27:16 +0100
Lines: 74
Mime-Version: 1.0
To: jon <ph@qyd.com>

Well, here is one that works, no doubt folks will not approve of using csh and
can do it in less lines with sh/ksh!

It isn't bombproof, it won't check wether the pts/# is still open (I have got
loads of them that are no longer active in my name, but if the user is not
logged on wheb the script starts and has no active pts/# the it seems to work
OK.

Thats whiles away some time on a friday afternoon!

Best wishes

Reg Smith

#!/bin/csh
# check first argument is supplied (a username to check for)

if ($#argv == 0) then
        echo "Please supply username as first argument"
        exit (1)
endif

set whoamilookingfor=$1

# Check username is valid
id $whoamilookingfor

if ( $status == 1 ) then
        exit (1)
endif

# Need to set variable to null (unset breaks if() lower down)
set tty=""

# Check who is logged on every 20 seconds

# infinite loop
while (1)

        #filter output of w command to see if user is logged on to which tty

        set tty=`w | grep $whoamilookingfor | tail -1 | awk '{print $2}'`

        if ($tty == "") then
                sleep 20
                continue
        endif

        echo "Hello $whoamilookingfor, you have just logged on"  > /dev/$tty

sleep 20

end


jon wrote:

> Sorry to barge in on the group but I am working on a college assignment and
> I am extremely stuck on the following question
>
> Any advice or pointers gratefully received..
>
> Question
> ***********
> Using the UNIX vi editor to write a Shell script that samples the list of
> logged in users every 20 seconds, waiting for a specific user to log in; as
> soon as that user’s login name is detected, a standard message (a ‘here’
> document) should be sent to their terminal
> ???
> Thanks
> Stripe




-- 

Yahoo : Winternet : TC Guide  : Files of Local Interest Enter Sysinfo.com :



Hosted by: Enter:  sysinfo.com


©copyright 1995-2002 sysinfo.com