Re: [SLUG] script permissions, etc
It's a good idea to use variables for storing the filenames used. It's also a good idea to use an absolute path when accessing the file. eg: my_user = voytek ccc_final = /var/tmp/ccc ccc_html = http:.../ccc.html ccc_txt = /var/tmp/ccc.txt ccc_bod = /var/tmp/ccc.bod wget ... $ccc_html ... links -dump $ccc_html $ccc_txt ... awk '/Page/, /References/ { print }' $ccc_txt $ccc_bod ... mail -s ccc list $my_user $ccc_final etc. Chris- On Mon, May 9, 2011 at 8:59 AM, Voytek Eymont li...@sbt.net.au wrote: I'm trying to put together a basic script, it works fine when I run it as root, but, I'm having issues when I try to run as 'voytek' $ ls -al /usr/local/bin/ccc -rwxr-x--- 1 root voytek 1409 May 9 08:19 /usr/local/bin/ccc /usr/local/bin/ccc: line 16: ccc.txt: Permission denied mv: overwrite `ccc.old', overriding mode 0644? rm: remove write-protected regular file `logout.html'? rm: remove write-protected regular file `logout.html'? logout.html: Permission denied script fetches a html page, parses it several times, then emails some text from it when starting the script should I say 'cd /var/tmp' (to have temp files in/var/tmp?) should I prefix full path to intermediate files ( /var/tmp/body.txt?) --- wget http://dom.tld/main.htm wget ccc.html echo dump to text, get rid of blanks links -dump ccc.html ccc.txt ## get rid of blank lines awk '/Page/, /References/ { print }' ccc.txt ccc.bod ## Better remove all leading and trailing whitespace from end of each line: sed 's/^[ \t]*//;s/[ \t]*$//' ccc.bod ccc.1 # delete lines matching pattern sed '/INT/d' ccc.1 ccc mail -s ccc list voytek ccc mv ccc ccc.old rm main.htm rm logout.html rm ccc.1 rm ccc.bod rm ccc.html rm logout.html rm my-cookies --- -- 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 permissions, etc
Voytek == Voytek Eymont li...@sbt.net.au writes: Voytek I'm trying to put together a basic script, it works fine when Voytek I run it as root, but, I'm having issues when I try to run as Voytek 'voytek' Voytek $ ls -al /usr/local/bin/ccc -rwxr-x--- 1 root voytek 1409 May Voytek 9 08:19 /usr/local/bin/ccc This looks OK. Voytek /usr/local/bin/ccc: line 16: ccc.txt: Permission denied mv: Voytek overwrite `ccc.old', overriding mode 0644? rm: remove Voytek write-protected regular file `logout.html'? rm: remove Voytek write-protected regular file `logout.html'? logout.html: Voytek Permission denied What directory are you running in? I'd add cd /var/tmp early in the script so you know you're running in a place you have write access to. Voytek script fetches a html page, parses it several times, then Voytek emails some text from it Voytek when starting the script should I say 'cd /var/tmp' (to have Voytek temp files in/var/tmp?) Yes. Actually, I'd do something like: TMP=/var/tmp/`basename $0`$$ mkdir -p $TMP cd $TMP trap 'cd /var/tmp; rm -rf $TMP' 0 to create a place where you can work, that'll get cleaned up afterwards. -- Dr Peter Chubb http://www.gelato.unsw.edu.au peterc AT gelato.unsw.edu.au http://www.ertos.nicta.com.au ERTOS within National ICT Australia -- 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 permissions, etc
Tmp has special permissions only the person that created it can delete it and generally global write is not enabled Clan up the tmp file reliably and you should have no problems. The is also a make temp call that gives you a reliably unique filename Ken Foskey On 09/05/2011, at 9:59 AM, Chris Donovan alienreside...@gmail.com wrote: It's a good idea to use variables for storing the filenames used. It's also a good idea to use an absolute path when accessing the file. eg: my_user = voytek ccc_final = /var/tmp/ccc ccc_html = http:.../ccc.html ccc_txt = /var/tmp/ccc.txt ccc_bod = /var/tmp/ccc.bod wget ... $ccc_html ... links -dump $ccc_html $ccc_txt ... awk '/Page/, /References/ { print }' $ccc_txt $ccc_bod ... mail -s ccc list $my_user $ccc_final etc. Chris- On Mon, May 9, 2011 at 8:59 AM, Voytek Eymont li...@sbt.net.au wrote: I'm trying to put together a basic script, it works fine when I run it as root, but, I'm having issues when I try to run as 'voytek' $ ls -al /usr/local/bin/ccc -rwxr-x--- 1 root voytek 1409 May 9 08:19 /usr/local/bin/ccc /usr/local/bin/ccc: line 16: ccc.txt: Permission denied mv: overwrite `ccc.old', overriding mode 0644? rm: remove write-protected regular file `logout.html'? rm: remove write-protected regular file `logout.html'? logout.html: Permission denied script fetches a html page, parses it several times, then emails some text from it when starting the script should I say 'cd /var/tmp' (to have temp files in/var/tmp?) should I prefix full path to intermediate files ( /var/tmp/body.txt?) --- wget http://dom.tld/main.htm wget ccc.html echo dump to text, get rid of blanks links -dump ccc.html ccc.txt ## get rid of blank lines awk '/Page/, /References/ { print }' ccc.txt ccc.bod ## Better remove all leading and trailing whitespace from end of each line: sed 's/^[ \t]*//;s/[ \t]*$//' ccc.bod ccc.1 # delete lines matching pattern sed '/INT/d' ccc.1 ccc mail -s ccc list voytek ccc mv ccc ccc.old rm main.htm rm logout.html rm ccc.1 rm ccc.bod rm ccc.html rm logout.html rm my-cookies --- -- 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 -- 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 permissions, etc
On Mon, May 9, 2011 10:52 am, Peter Chubb wrote: Voytek == Voytek Eymont li...@sbt.net.au writes: TMP=/var/tmp/`basename $0`$$ mkdir -p $TMP cd $TMP trap 'cd /var/tmp; rm -rf $TMP' 0 to create a place where you can work, that'll get cleaned up afterwards. Peter, Ken, Chris, many thanks this works good from terminal! I'm trying to run this from 'ostiaryd' what uid/gid to use, I'm '500' # Format is: # ACTION=secret,command (with path),[uid[,gid]] # If uid,gid not set, will use defaults. # Some samples. # Note: uid gid only allowed when ostiary runs as root #ACTION=Trillions,/tmp/ostiary/uidtest,520,101 ACTION=ccc,/usr/local/bin/ccc,500,500 tried 500/500 but get: May 9 11:21:48 waltoncr ostiaryd: Exec failed for command '/usr/local/bin/ccc 192.168.1.65': Exec format error -- Voytek -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html