Re: [SLUG] script help with grep or regex ?

2014-01-14 Thread peter
 lists == lists  li...@sbt.net.au writes:

lists I have a shell script that gets a web page, after around half
lists dozen sed/awk one liners I end up with like[1]:

lists I would like to extract all the 7 digit numeric values,
lists currently starting with '313', to use them further in the
lists script

Why not just something like:
sed  's/[^0-9]*\(313[0-9][0-9][0-9][0-9]\)[^0-9]*/\n\1\n/g'  |
sed -n '/^313[0-9][0-9][0-9][0-9]$/p'

This first splits out 7-digit numbers starting 313 into a line on
their own, then prints just those lines.

Peter C
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with grep or regex ?

2014-01-14 Thread Darragh Bailey
Hi,

or in perl :)

If there is other data in front
| perl -ne 'if ( =~ /(?!\w)(313[0-9]{4})(?![0-9])/) { print $1\n;}'

otherwise
| perl -ne 'print if /^313[0-9]{4}(?![0-9])/'



On 15 January 2014 13:45, pe...@chubb.wattle.id.au wrote:

  lists == lists  li...@sbt.net.au writes:

 lists I have a shell script that gets a web page, after around half
 lists dozen sed/awk one liners I end up with like[1]:

 lists I would like to extract all the 7 digit numeric values,
 lists currently starting with '313', to use them further in the
 lists script

 Why not just something like:
 sed  's/[^0-9]*\(313[0-9][0-9][0-9][0-9]\)[^0-9]*/\n\1\n/g'  |
 sed -n '/^313[0-9][0-9][0-9][0-9]$/p'

 This first splits out 7-digit numbers starting 313 into a line on
 their own, then prints just those lines.

 Peter C
 --
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html




-- 
Darragh Bailey
Nothing is foolproof to a sufficiently talented fool
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] script help with grep or regex ?

2014-01-13 Thread lists
I have a shell script that gets a web page, after around half dozen
sed/awk one liners I end up with like[1]:

I would like to extract all the 7 digit numeric values, currently starting
with '313', to use them further in the script

I'm hoping there is some better way ? (rather what I'm doing, 'grep 313')

[1]---
Page: 1 Items: 1 - 2

Items(Total: 2 displaying 2)

3137973
stf, Stuff, morestuff, Stuff2:stuff3,
Date: 14/01/2014, Time: 09:30 AM
14/01/2014 09:30
Notes(0)

3137966
stf, Stuff, morestuff, Stuff2:stuff3,
Date: 06/02/2014, Time: 09:30 AM
06/02/2014 09:30
Notes(0)



-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with grep or regex ?

2014-01-13 Thread kfoskey


There are man html reader libraries out there.  I have used one for perl for 
example.   It enables you to look for some other tag to find your data (eg 
the css class name of that particular element) and rip the data by walking 
the html tree.


Pick a language and let us know I am sure you will get specific 
recommendations on html reader / parser libraries.  (eg html agility for C#)


Ta
Ken


-Original Message- 
From: li...@sbt.net.au

Sent: Tuesday, January 14, 2014 12:35 PM
To: slug@slug.org.au
Subject: [SLUG] script help with grep or regex ?

I have a shell script that gets a web page, after around half dozen
sed/awk one liners I end up with like[1]:

I would like to extract all the 7 digit numeric values, currently starting
with '313', to use them further in the script

I'm hoping there is some better way ? (rather what I'm doing, 'grep 313')

[1]---
Page: 1 Items: 1 - 2

Items(Total: 2 displaying 2)

3137973
stf, Stuff, morestuff, Stuff2:stuff3,
Date: 14/01/2014, Time: 09:30 AM
14/01/2014 09:30
Notes(0)

3137966
stf, Stuff, morestuff, Stuff2:stuff3,
Date: 06/02/2014, Time: 09:30 AM
06/02/2014 09:30
Notes(0)



--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html



-
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4259 / Virus Database: 3658/6997 - Release Date: 01/12/14 




-
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4259 / Virus Database: 3658/6997 - Release Date: 01/12/14

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with grep or regex ?

2014-01-13 Thread lists
On Tue, January 14, 2014 12:45 pm, kfos...@tpg.com.au wrote:

 There are man html reader libraries out there.  I have used one for perl
 for example.   It enables you to look for some other tag to find your data
 (eg
 the css class name of that particular element) and rip the data by walking
  the html tree.

 Pick a language and let us know I am sure you will get specific
 recommendations on html reader / parser libraries.  (eg html agility for
 C#)

Ken,

thanks. I think you might have anwsered my next question already:

what I'm doing is like: wget url  html; lynx html  text

initially, I was getting no text output, as html was html5 something;

neither links nor lynx knew how to process html, blank output

after installing latest dev build lynx, I started getting data in text;

- some data in text gets 'trimmed' at 30 cols;
editing html 'cols=30' and, re-dumping text fixes such fields;

- some other data in text gets 'trimmed' at 20 cols;
I can't find any 'cols=' statements in html, haven't found a way to output
all data from these fields

opening html in lynx, these fields are also 'trimmed' on screen, BUT,
scrollable 

so, I guess the libraries you suggest would overcome such html5? issues?

even it's somewhat outside of my abilities, I guess I could try Perl?
(if I can find some sample code)

thanks again
V

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with grep or regex ?

2014-01-13 Thread Jiří Baum
Hi,

 thanks. I think you might have anwsered my next question already:

 what I'm doing is like: wget url  html; lynx html  text

Ah, skip the lynx step. Just work with the html directly.

All the tools (sed, awk, grep) can work directly with html.

 even it's somewhat outside of my abilities, I guess I could try Perl?
 (if I can find some sample code)

To some extent it depends on how variable the original page is.

Once you skip the lynx step, you might even find that it's trivial. For
instance, the values you want might all be in a tag with a single, fixed
class or id; you can just grep for that, then strip off the HTML
with sed.

This is especially likely if they're all from the same website,
generated from a single template.


Jiri
-- 
Jiří Baum j...@baum.com.au
Sabik Software Solutions Pty Ltd
0413 183 117
http://www.baum.com.au/sabik
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Re: [SLUG] script help with grep or regex ?

2014-01-13 Thread lists
On Tue, January 14, 2014 1:31 pm, Jiří Baum wrote:

 Ah, skip the lynx step. Just work with the html directly.
 All the tools (sed, awk, grep) can work directly with html.
 To some extent it depends on how variable the original page is.

 Once you skip the lynx step, you might even find that it's trivial. For
 instance, the values you want might all be in a tag with a single, fixed
 class or id; you can just grep for that, then strip off the HTML
 with sed.

 This is especially likely if they're all from the same website,
 generated from a single template.

Jiri, thanks

the page is reasonably constant (until any fixes?)

all the values I want are in a single 6000 char line, how do I break the
6000 char line into individual vaules, 'grep any_value file' gives me the
whole 6000 chars ?

V


-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with grep or regex ?

2014-01-13 Thread Jiří Baum
Hi,

 the page is reasonably constant (until any fixes?)

Yeah, that's always a danger...

 all the values I want are in a single 6000 char line, how do I break the
 6000 char line into individual vaules, 'grep any_value file' gives me the
 whole 6000 chars ?

Several ways, probably the easiest is to use the --only-matching option
on grep. That way, it will only return the parts it matched.

For instance, you might write:
grep -o 'foo class=bar[0-9]*/foo' file


Another way would be to use sed to add a newline at some reasonable
points, for instance at the beginning of each tag.


Finally, if you use Perl, you can just search for
/foo class=bar([0-9]*)\/foo/
which will give you the parts you want directly in $1.


Jiri
-- 
Jiří Baum j...@baum.com.au
Sabik Software Solutions Pty Ltd
0413 183 117
http://www.baum.com.au/sabik
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

[SLUG] script help with unexpected token/variable

2011-08-21 Thread Voytek Eymont
I have a short script (which I think? used to work on the old server...)
that I'm having problems with:

I want to run archivemail against all mailboxes in:
/var/mail/vhosts/domain.tld/*@domain.tld

this is what I need to run:

:/var/mail/vhosts/aa.com.au# sudo -u#5000  archivemail -d90 r...@aa.com.au


the script fails with

# archmail aa.com.au
/usr/local/bin/archmail: line 19: syntax error near unexpected token `sudo'
/usr/local/bin/archmail: line 19: `  sudo -u#5000  archivemail -d90 $j '

script:
--
# cat /usr/local/bin/archmail
#!
 case $# in
  1)
  DOMAIN=$1
  ;;
  *)
echo Usage: $0 domain.name 12
echo this archives $1  Maildirs 
echo all mail over 90 days is gzipped
exit
;;
 esac

if [ -s /var/mail/vhosts/$1 ] ; then

cd /var/mail/vhosts/$1

for j in *@*
  sudo -u#5000  archivemail -d90 $j
done

exit
fi

echo no such domain $1
exit
---



(I should really know by now how to do this...)

-- 
Voytek

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with unexpected token/variable

2011-08-21 Thread Chris Donovan
 for j in *@*
do
  sudo -u#5000  archivemail -d90 $j
 done

Chris-
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with unexpected token/variable

2011-08-21 Thread Voytek Eymont

On Mon, August 22, 2011 11:37 am, Chris Donovan wrote:
 for j in *@*
 do
  sudo -u#5000  archivemail -d90 $j
 done

Chris, thanks

all's working good







-- 
Voytek

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help with unexpected token/variable

2011-08-21 Thread Nick Andrew
On Mon, Aug 22, 2011 at 09:55:34AM +1100, Voytek Eymont wrote:
 # archmail aa.com.au
 /usr/local/bin/archmail: line 19: syntax error near unexpected token `sudo'
 /usr/local/bin/archmail: line 19: `  sudo -u#5000  archivemail -d90 $j '
 
 script:
 --
 # cat /usr/local/bin/archmail
 #!

It looks like your script is missing a correct shebang line.

Try:

   #!/bin/bash

Nick.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help

2008-07-16 Thread Voytek Eymont

On Wed, July 16, 2008 10:05 am, [EMAIL PROTECTED] wrote:


Dave,
thanks

I think I have brackets or quotes wrong?

# ./t
./t: line 5: echo: No such file or directory



#!/bin/bash

trafrep=$(lynx -dump
http://rta.nsw.gov.au/trafficreports/sydney/sydney_east_inner_west.html |
sed -n -e
'/Last refreshed/{:a;N;/Road Works/!ba;p;}')
mutt -s Traffic Report East Inner West [EMAIL PROTECTED]  echo ${trafrep}

-- 
Voytek

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help

2008-07-16 Thread Amos Shapira
2008/7/16 Voytek Eymont [EMAIL PROTECTED]:

 On Wed, July 16, 2008 10:05 am, [EMAIL PROTECTED] wrote:


 Dave,
 thanks

 I think I have brackets or quotes wrong?

He used input redirection instead of a pipe:

 mutt -s Traffic Report East Inner West [EMAIL PROTECTED]  echo ${trafrep}

Should read:

echo ${trafrep} | mutt -s Traffic Report East Inner West [EMAIL PROTECTED]

--Amos
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] script help

2008-07-15 Thread Voytek Eymont
I'm trying to put together a basic script to get 'on demand' traffic info
to my handheld, all commands more or less work as desired, but, I would
like to make a 'proper script' out of it:

I guess I should put the 'temp' files in /var/tmp ?
and, send screen output to /dev/null ?
any help or suggestions appreciated:

# ./traffic
--09:34:15-- 
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg
   = `citywestlink.jpg'
Resolving rta.nsw.gov.au... 163.189.7.150, 163.189.217.150
Connecting to rta.nsw.gov.au|163.189.7.150|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22,125 (22K) [image/jpeg]

100%[] 22,125--.--K/s

09:34:15 (2.38 MB/s) - `citywestlink.jpg' saved [22125/22125]

Corrupt JPEG data: 736 extraneous bytes before marker 0xda



#!/bin/sh
lynx -dump
http://rta.nsw.gov.au/trafficreports/sydney/sydney_east_inner_west.html | 
sed -n -e '/Last refreshed/{:a;N;/Road Works/!ba;p;}'  traf.rep

wget
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg

jpegtran -rotate 270   citywestlink.jpg  citymap.jpg

mutt -s Traffic Report East Inner West  -a citymap.jpg [EMAIL PROTECTED]
 traf.rep

rm traf.rep
rm *.jpg
-

-- 
Voytek

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help

2008-07-15 Thread daveg
For starters I guess you could throw in a -q to wget to stop it from  
outputting but I guess sending output to /dev/null (as long as you  
aren't fussed when things fail) should be enough.


Quoting Voytek Eymont [EMAIL PROTECTED]:


I'm trying to put together a basic script to get 'on demand' traffic info
to my handheld, all commands more or less work as desired, but, I would
like to make a 'proper script' out of it:

I guess I should put the 'temp' files in /var/tmp ?
and, send screen output to /dev/null ?
any help or suggestions appreciated:

# ./traffic
--09:34:15--
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg
   = `citywestlink.jpg'
Resolving rta.nsw.gov.au... 163.189.7.150, 163.189.217.150
Connecting to rta.nsw.gov.au|163.189.7.150|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22,125 (22K) [image/jpeg]

100%[] 22,125--.--K/s

09:34:15 (2.38 MB/s) - `citywestlink.jpg' saved [22125/22125]

Corrupt JPEG data: 736 extraneous bytes before marker 0xda



#!/bin/sh
lynx -dump
http://rta.nsw.gov.au/trafficreports/sydney/sydney_east_inner_west.html |
sed -n -e '/Last refreshed/{:a;N;/Road Works/!ba;p;}'  traf.rep

wget
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg

jpegtran -rotate 270   citywestlink.jpg  citymap.jpg

mutt -s Traffic Report East Inner West  -a citymap.jpg [EMAIL PROTECTED]
 traf.rep

rm traf.rep
rm *.jpg
-

--
Voytek

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html





--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help

2008-07-15 Thread daveg

#!/bin/bash
trafrep=$(lynx -dump
 http://rta.nsw.gov.au/trafficreports/sydney/sydney_east_inner_west.html |
sed -n -e '/Last refreshed/{:a;N;/Road Works/!ba;p;}')
wget -q
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg  
-O- | jpegtran -rotate 270  citymap.jpg


mutt -s Traffic Report East Inner West -a citymap.jpg [EMAIL PROTECTED]
 echo ${trafrep}
rm *.jpg

Quoting Voytek Eymont [EMAIL PROTECTED]:


I'm trying to put together a basic script to get 'on demand' traffic info
to my handheld, all commands more or less work as desired, but, I would
like to make a 'proper script' out of it:

I guess I should put the 'temp' files in /var/tmp ?
and, send screen output to /dev/null ?
any help or suggestions appreciated:

# ./traffic
--09:34:15--
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg
   = `citywestlink.jpg'
Resolving rta.nsw.gov.au... 163.189.7.150, 163.189.217.150
Connecting to rta.nsw.gov.au|163.189.7.150|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22,125 (22K) [image/jpeg]

100%[] 22,125--.--K/s

09:34:15 (2.38 MB/s) - `citywestlink.jpg' saved [22125/22125]

Corrupt JPEG data: 736 extraneous bytes before marker 0xda



#!/bin/sh
lynx -dump
http://rta.nsw.gov.au/trafficreports/sydney/sydney_east_inner_west.html |
sed -n -e '/Last refreshed/{:a;N;/Road Works/!ba;p;}'  traf.rep

wget
http://rta.nsw.gov.au/trafficreports/cameras/camera_images/citywestlink.jpg

jpegtran -rotate 270   citywestlink.jpg  citymap.jpg

mutt -s Traffic Report East Inner West  -a citymap.jpg [EMAIL PROTECTED]
 traf.rep

rm traf.rep
rm *.jpg
-

--
Voytek

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html





--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] script help

2008-07-15 Thread Peter Hardy
On Wed, 2008-07-16 at 09:39 +1000, Voytek Eymont wrote:
 I'm trying to put together a basic script to get 'on demand' traffic info
 to my handheld, all commands more or less work as desired, but, I would
 like to make a 'proper script' out of it:
 
 I guess I should put the 'temp' files in /var/tmp ?
 and, send screen output to /dev/null ?
 any help or suggestions appreciated:

Rather than just redirecting all output to /dev/null , it's worth
checking if the commands you're using have a quiet option. As previous
posters have already pointed out, wget's -q option is one.

Also, look in to using the mktemp command to create temporary filenames.

-- 
Pete

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script help

2005-09-22 Thread Vino Fernando Crescini



yep, and if I cat the file they are displayed that way


I know it's a longshot, but can you confirm that there are
no ^M (CR) characters in the end of each line in
allusers.txt?


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Vino Fernando Crescini
Sent: Thu, 22. September 2005 3:47 PM
To: SLug Users
Subject: Re: [SLUG] Script help




#!/bin/bash
while read name; do
grep $name smbpasswd;
done  allusers.txt



are the names in allusers.txt listed one per line?



--
Vino Fernando Crescini Intelligent Systems Laboratory
   School of Computing  IT
phone: +61 2 4736 0140 University of Western Sydney
email: [EMAIL PROTECTED] Locked Bag 1797
web: www.cit.uws.edu.au/~jcrescin  Penrith South DC NSW 1797

Scanned by SCIT E-Mail Gateway http://www.cit.uws.edu.au


--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] Script help

2005-09-21 Thread Simon
Hi all,
Can anyone tell me why I get no output from this script? I am not good
at writing my own so modify others. I have tested that it is reading the
allusers.txt by adding an echo $name

#!/bin/bash
while read name; do
grep $name smbpasswd;
done  allusers.txt

My basic problem is I have an smbpasswd file where for a couple of years
users were not removed properly so that there are about 350 extra users
in the smbpasswd file - I want to cut it down to the right size - and be
able to reuse the usernames. I have a complete list 'allusers.txt' of
all the valid users. Once this worked I was just going to pipe the
output to a nwe file.

OLMC
Simon Bryan
IT Manager
[EMAIL PROTECTED]
LMB 14
North Parramatta
Direct Number:88381200
SwitchBoard: 96833300
fax: 98901466
mobile: 0414238002


-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script help

2005-09-21 Thread Vino Fernando Crescini

#!/bin/bash
while read name; do
grep $name smbpasswd;
done  allusers.txt


are the names in allusers.txt listed one per line?

--
Vino Fernando Crescini Intelligent Systems Laboratory
   School of Computing  IT
phone: +61 2 4736 0140 University of Western Sydney
email: [EMAIL PROTECTED] Locked Bag 1797
web: www.cit.uws.edu.au/~jcrescin  Penrith South DC NSW 1797

Scanned by SCIT E-Mail Gateway http://www.cit.uws.edu.au


--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


RE: [SLUG] Script Help

2005-05-11 Thread Simon
Thanks to all who replied, I have seen where my error is and have
numerous alternatives, the task is now underway properly.

Cheers
SImon

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Sonia Hamilton
 Sent: Wed, 11. May 2005 3:19 PM
 To: slug@slug.org.au
 Subject: Re: [SLUG] Script Help
 
 
 * On Wed, May 11, 2005 at 01:48:35PM +1000, Simon wrote:
  Hi all,
  Why is the following script ripping out every directory rather than 
  just those in 'studentfile'
  
  #!/bin/bash
  while read name; do
   cd $name
 
 Fails here if directory $name doesnt exist; next line deletes 
 everything.
 
   rm -fvr *
   cd ..
   rmdir $name
  done  studentlist
 
 --
 Sonia Hamilton. GPG key A8B77238.
 .
 Type cat vmlinuz  /dev/audio to hear the voice of $DEITY.
 -- 
 SLUG - Sydney Linux User's Group Mailing List - 
http://slug.org.au/ Subscription info and FAQs:
http://slug.org.au/faq/mailinglists.html

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-11 Thread Matthew Hannigan
On Wed, May 11, 2005 at 03:24:58PM +1000, Rick Welykochy wrote:
 In C, one wouldn't (I hope) call a function and then ignore  possible
 error return, i.e.
  [  ]
 So why eschew the same when programming in the shell?
 
 while read name; do
if cd $name; then
   rm -fvr *
   cd ..
   rmdir $name
else
   echo 12 skipping directory $name: could not cd
fi
 done  studentlist

Don't stop there!  The defensive programmer
might also

1. quote vars ie. $name
2. ensure all vars are actually define before use i.e. set -u
3. check the return of all commands, i.e. set -e
4. perhaps have a trap ERR ' ... ' because of 3.
e.g. trap 'echo 2 Internal error $0 line $LINENO' ERR
5. use a real language :-)

btw, the rmdir is not going to work, because rm * is not going to
remove dotfiles.

Now the tempation might be to do rm -rf .*.  But that
will remove .. and much unhappiness will ensue.

Not doing rm -something* is good advice.


Matt




-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-11 Thread [EMAIL PROTECTED]
 It would seem using somthing like xargs may be appropriate.

xargs studentlist rm -switches

Xargs will ensure the command argument buffer is chopped into appropriate sized 
chunks.

Cheers
Shane
 Peter Miller [EMAIL PROTECTED] wrote: 
On Wed, 2005-05-11 at 13:58 +1000, Julio Cesar Ody wrote:

 $ for dirname in `cat studentlist`; do rm -rf $dirname/*; done

cat studentlist | while read dirname; do rm -rf $dirname/*; done

this will cope more elegantly with large numbers of line in the slug
student list file.  The line


-- 
Regards
Peter Miller [EMAIL PROTECTED]
/\/\*http://www.canb.auug.org.au/~millerp/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] Script Help

2005-05-10 Thread Simon
Hi all,
Why is the following script ripping out every directory rather than just
those in 'studentfile'

#!/bin/bash
while read name; do
 cd $name
 rm -fvr *
 cd ..
 rmdir $name
done  studentlist


OLMC
Simon Bryan
IT Manager
[EMAIL PROTECTED]
LMB 14
North Parramatta
tel: 96833300
fax: 98901466
mobile: 0414238002


-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Vino Fernando Crescini

Simon wrote:
Hi all,
Why is the following script ripping out every directory rather than just
those in 'studentfile'
#!/bin/bash
while read name; do
 cd $name
 rm -fvr *
 cd ..
 rmdir $name
done  studentlist

while read name; do
  rm -fvr $name
done  studentlist
--
Vino Fernando Crescini Intelligent Systems Laboratory
   School of Computing  IT
phone: +61 2 4736 0140 University of Western Sydney
email: [EMAIL PROTECTED] Locked Bag 1797
web: www.cit.uws.edu.au/~jcrescin  Penrith South DC NSW 1797
What's a battle?
--Ralph Wiggum
  Whacking Day (Episode 9F18)
Scanned by SCIT E-Mail Gateway http://www.cit.uws.edu.au
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Julio Cesar Ody
 Why is the following script ripping out every directory rather than just
 those in 'studentfile'

You mean studentlist?

Anyway, you could try:

$ for dirname in `cat studentlist`; do rm -rf $dirname/*; done

Will remove everything inside each folder listed in a file called
studentlist, located in the same directory you're running the script.

Hope it helps.


On 5/11/05, Simon [EMAIL PROTECTED] wrote:
 Hi all,
 Why is the following script ripping out every directory rather than just
 those in 'studentfile'
 
 #!/bin/bash
 while read name; do
  cd $name
  rm -fvr *
  cd ..
  rmdir $name
 done  studentlist
 
 
 OLMC
 Simon Bryan
 IT Manager
 [EMAIL PROTECTED]
 LMB 14
 North Parramatta
 tel: 96833300
 fax: 98901466
 mobile: 0414238002
 
 
 --
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
 


-- 
Julio C. Ody
http://www.livejournal.com/users/julioody/
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Peter Rundle
Simon scribed;
Why is the following script ripping out every directory rather than just
those in 'studentfile'
#!/bin/bash
while read name; do
cd $name
rm -fvr *
cd ..
rmdir $name
done  studentlist
 

Repeat after me:   Never use a star with rm -r !
In your script what will happen if there is a name in the list that 
doesn't exist as a directory?
cd $name  will fail leaving you in the current directory.
rm -r *  will then remove everything in the current directory..

as Vino  said do this;
while read name; do
  rm -fvr $name
done  studentlist
much safer.
HTH
P
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Peter Miller
On Wed, 2005-05-11 at 13:58 +1000, Julio Cesar Ody wrote:

 $ for dirname in `cat studentlist`; do rm -rf $dirname/*; done

cat studentlist | while read dirname; do rm -rf $dirname/*; done

this will cope more elegantly with large numbers of line in the slug
student list file.  The line


-- 
Regards
Peter Miller [EMAIL PROTECTED]
/\/\*http://www.canb.auug.org.au/~millerp/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.


signature.asc
Description: This is a digitally signed message part
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

RE: [SLUG] Script Help

2005-05-10 Thread Simon


 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Peter Rundle
 Sent: Wed, 11. May 2005 2:11 PM
 To: SLUG
 Subject: Re: [SLUG] Script Help
 
 
 Simon scribed;
 
 Why is the following script ripping out every directory rather than 
 just those in 'studentfile'
 
 #!/bin/bash
 while read name; do
  cd $name
  rm -fvr *
  cd ..
  rmdir $name
 done  studentlist
   
 
 Repeat after me:   Never use a star with rm -r !


Ah, exactly what happened. OK, I have given myself six of the best
and promise never to do that again!
Can I get some credit for being able to restore them from the backup
:-)




 
 In your script what will happen if there is a name in the list that 
 doesn't exist as a directory?
 cd $name  will fail leaving you in the current directory.
 rm -r *  will then remove everything in the current directory..
 
 as Vino  said do this;
 
  while read name; do
rm -fvr $name
  done  studentlist
 
 much safer.
 
 HTH
 
 P
 
 -- 
 SLUG - Sydney Linux User's Group Mailing List - 
http://slug.org.au/ Subscription info and FAQs:
http://slug.org.au/faq/mailinglists.html

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Sonia Hamilton
* On Wed, May 11, 2005 at 01:48:35PM +1000, Simon wrote:
 Hi all,
 Why is the following script ripping out every directory rather than just
 those in 'studentfile'
 
 #!/bin/bash
 while read name; do
  cd $name

Fails here if directory $name doesnt exist; next line deletes everything.

  rm -fvr *
  cd ..
  rmdir $name
 done  studentlist

--
Sonia Hamilton. GPG key A8B77238.
.
Type cat vmlinuz  /dev/audio to hear the voice of $DEITY.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Alexander Samad
On Wed, May 11, 2005 at 02:10:40PM +1000, Peter Rundle wrote:
 Simon scribed;
 
 Why is the following script ripping out every directory rather than just
 those in 'studentfile'
 
 #!/bin/bash
 while read name; do
 cd $name
 rm -fvr *
 cd ..
 rmdir $name
 done  studentlist
  
 
 Repeat after me:   Never use a star with rm -r !
 
 In your script what will happen if there is a name in the list that 
 doesn't exist as a directory?
 cd $name  will fail leaving you in the current directory.
 rm -r *  will then remove everything in the current directory..
 
 as Vino  said do this;
 
 while read name; do
   rm -fvr $name

might be best to do this incase there are special characters in the
directory name !


   rm -fvr $name

 done  studentlist
 
 much safer.
 
 HTH
 
 P
 
 -- 
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
 


signature.asc
Description: Digital signature
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Re: [SLUG] Script Help

2005-05-10 Thread Julio Cesar Ody
Yeah, I replied, but not to the list. It follows:

// begin reply //

Still, the previous reply makes an interesting point that I
overlooked. Using star in rm -r is  reckless, in general. But by
issuing a rm -rf $name will remove the directory along with it's
contents, whereas rm -rf $name/* wipes only the content out. Up to
you to decide what's best.

A little bit paranoia  =) , but since the subject always leaves us a
bunch of options, maybe it's worth mentioning: given the fact that
this is probably a non-interactive app, we're assuming a line will
never contain a front-slash plus some other folder name. One fine day,
the app finds a line containing /etc, you'll end up removing /etc/*.
Empty lines should not be a problem because bash (and I don't know
what's the behavior of shells in this case) will ignore them.

That goes with the user you're running the script as, possibility of
such line getting into the file, and lots of things you guys probably
know.

My I-owe-you-2-cents tip. Cheers.

// end reply //


On 5/11/05, Alexander Samad [EMAIL PROTECTED] wrote:
 On Wed, May 11, 2005 at 02:10:40PM +1000, Peter Rundle wrote:
  Simon scribed;
 
  Why is the following script ripping out every directory rather than just
  those in 'studentfile'
  
  #!/bin/bash
  while read name; do
  cd $name
  rm -fvr *
  cd ..
  rmdir $name
  done  studentlist
  
  
  Repeat after me:   Never use a star with rm -r !
 
  In your script what will happen if there is a name in the list that
  doesn't exist as a directory?
  cd $name  will fail leaving you in the current directory.
  rm -r *  will then remove everything in the current directory..
 
  as Vino  said do this;
 
  while read name; do
rm -fvr $name
 
 might be best to do this incase there are special characters in the
 directory name !
 
rm -fvr $name
 
  done  studentlist
 
  much safer.
 
  HTH
 
  P
 
  --
  SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
  Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
 
 
 
 BodyID:116513997.2.n.logpart (stored separately)
 
 --
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
 
 


-- 
Julio C. Ody
http://rootshell.be/~julioody
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Script Help

2005-05-10 Thread Rick Welykochy
Simon wrote:

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Peter Rundle
Sent: Wed, 11. May 2005 2:11 PM
To: SLUG
Subject: Re: [SLUG] Script Help

Simon scribed;

Why is the following script ripping out every directory rather than 
just those in 'studentfile'

#!/bin/bash
while read name; do
cd $name
rm -fvr *
cd ..
rmdir $name
done  studentlist

Repeat after me:   Never use a star with rm -r !

Ah, exactly what happened. OK, I have given myself six of the best
and promise never to do that again!
Can I get some credit for being able to restore them from the backup
:-)
In C, one wouldn't (I hope) call a function and then ignore  possible
error return, i.e.
if (chdir(path) == 0)
{
/* do your thang */
}
else
{
/* handle error: see errno */
}
So why eschew the same when programming in the shell?
while read name; do
   if cd $name; then
  rm -fvr *
  cd ..
  rmdir $name
   else
  echo 12 skipping directory $name: could not cd
   fi
done  studentlist
cheers
rickw

--
_
Rick Welykochy || Praxis Services
People who enjoy eating sausage and obey the law should not watch either being 
made.
 -- Otto von Bismarck
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] Script help needed

2001-04-25 Thread Simon Bryan

HI,
I have a script I downloaded and have been able to make a couple of mods 
to. The script is called Addpopusers and takes input from a text file and 
creates the users for me. However now I do not want to create passwords as 
the system will authenticate against an NT server using PAM. The users are 
needed to allow for email from within AUC. Can someone look at the code 
below and tell me how to modify this to prevent the creation of a password 
for each user. My alternative is to let it create identical passwords and 
then use an editor to edit 'shadow'. BTW $passplain is set in a preceding 
section of the script, could I just set that to ?

# Now add our new user with home directory '$homebase$loginname' comment 
'real name,,,poponly' to group '$group' with shell '$ushell' to expire on 
'dec 30 this year' and get ouput if exists to flag file
 `groupadd $Group/dev/null 21/dev/null`
 `useradd -m -d $homebase$loginname -c $name,,,$comment -g 
$Group -s $ushell -k /etc/skeleton -e $acct_expire -p $passwd -O 
UID_MIN=$uid_min -O UID_MAX=$uid_max -O GID_MIN=$gid_min -O 
GID_MAX=$gid_max $loginname ./user.exists 21`
 err=`cat ./user.exists` # See if we have a dupe
 fi
 passwd=$passplain
 do_output    Jump to file and screen output
 if [ ${#err} -eq 0  ] ; then
 return 1
 else
 return 0

 fi
}




Simon Bryan

IT Manager
OLMC Parramatta
http://www.olmc.nsw.edu.au



-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug



Re: [SLUG] Script help needed

2001-04-25 Thread Del

Simon Bryan wrote:
 
 HI,
 I have a script I downloaded and have been able to make a couple of mods
 to. The script is called Addpopusers and takes input from a text file and
 creates the users for me. However now I do not want to create passwords as
 the system will authenticate against an NT server using PAM. The users are
 needed to allow for email from within AUC. Can someone look at the code
 below and tell me how to modify this to prevent the creation of a password
 for each user. My alternative is to let it create identical passwords and
 then use an editor to edit 'shadow'. BTW $passplain is set in a preceding
 section of the script, could I just set that to ?

OK, but depending on how you have your PAM set up, you may want / need to
have passwords in the /etc/passwd or /etc/shadow files.  This is a fallback
password that the user can log in with if the NT domain controller is not
responding.

Normally, I set this to something useful for the root user, and useless for
other users (I use an LDAP server, not an NT server, but the concept is
the same).

  `useradd -m -d $homebase$loginname -c $name,,,$comment -g
 $Group -s $ushell -k /etc/skeleton -e $acct_expire -p $passwd -O
 UID_MIN=$uid_min -O UID_MAX=$uid_max -O GID_MIN=$gid_min -O
 GID_MAX=$gid_max $loginname ./user.exists 21`

Just before this line, set $passwd to something random.  eg:

passwd=`echo $$`  (really simple case), or
passwd=AnyStRiNg$$and`date '+%s'` or

# do something clever with a random number generator.

Del

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug



Re: [SLUG] Script help needed

2001-04-25 Thread John Ferlito

On Thu, Apr 26, 2001 at 11:04:43AM +1000, Simon Bryan wrote:
 HI,
 I have a script I downloaded and have been able to make a couple of mods 
 to. The script is called Addpopusers and takes input from a text file and 
 creates the users for me. However now I do not want to create passwords as 
 the system will authenticate against an NT server using PAM. The users are 
 needed to allow for email from within AUC. Can someone look at the code 
 below and tell me how to modify this to prevent the creation of a password 
 for each user. My alternative is to let it create identical passwords and 
 then use an editor to edit 'shadow'. BTW $passplain is set in a preceding 
 section of the script, could I just set that to ?
 
If you don't set a password using -p with useradd then the
account is disabled by default. ie no password is set.

-- 
John Ferlito
Senior Engineer - Bulletproof Networks
ph: +61 (0) 410 519 382
http://www.bulletproof.net.au/

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug



Re: [SLUG] Script help needed

2001-04-25 Thread Simon Bryan

Thanks for the help. I seem to have it working satisfactorily now.

At 11:47 26/04/2001, you wrote:
Simon Bryan wrote:
 
  Just checking, you are saying I should actually create a password,

Yes

  just
  make it random

Yes

  (the script will do this for me),

The examples I gave you are really badly unrandom easily guessable
passwords.  I suggest you do something more clever.  man -k random on
your system might give you ideas.

  then ensure in my pam
  module that it checks the NT server first, then these passwords will be
  irrelevant anyway?

Yup.

Here is what I use in /etc/pam.d/login:

#%PAM-1.0
auth   required /lib/security/pam_securetty.so
auth   required /lib/security/pam_nologin.so
auth   sufficient   /lib/security/pam_ldap.so
auth   required /lib/security/pam_pwdb.so shadow nullok
accountsufficient   /lib/security/pam_ldap.so
accountrequired /lib/security/pam_pwdb.so
password   required /lib/security/pam_cracklib.so
password   required /lib/security/pam_ldap.so
password   required /lib/security/pam_pwdb.so nullok use_authtok md5 
shadow
sessionrequired /lib/security/pam_pwdb.so
sessionoptional /lib/security/pam_console.so

Del



Simon Bryan

IT Manager
OLMC Parramatta
http://www.olmc.nsw.edu.au



-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug