Re: Re: bash Shell Scripting Question
On 09/20/2012 04:29, Polytropon wrote: Correct. You could use different approaches which may or may not fail due to the directory names you will encounter (like directories with spaces or special characters). #!/bin/sh for DIR in `ls -LF | grep \/`; do cd ${DIR} # do stuff done Or you can use piping: #!/bin/sh ls -LF | grep \/ | while read DIR; do cd ${DIR} # do stuff done I'm quite confident there are even more elegant and fault- tolerant solutions. You would maybe have to tweak the ls command or play with IFS (space or newline). Even if you start quoting ${DIR}, the first one will fail at least for names containing spaces, the second one at least for names starting with spaces. As you said, you would have to change IFS to maybe slash and newline, assuming that you do not have names containing newlines, in which case the approach cannot work. I understand that you want all directories and links to directories not starting with a period. How about trying all files not starting with a period and skipping the non directories: #!/bin/sh for DIR in * do cd $DIR /dev/null 21 || continue pwd cd - /dev/null done This one works with names containing spaces or even newlines and does not even need to spawn external commands or subshells. It may have other caveats, though. Cheers, Jan Henrik ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash Shell Scripting Question
Many thanks! The for loop was what was needed. Polytropon writes: Just a sidenote: If you're not using bash-specific functionality and intend to make your script portable, use #!/bin/sh instead. I always start out that way for that very reason. I needed some random number functions and arithmetic for another part of the script so I ended up going to bash. while read dirname; do Attention: dirname (/usr/bin/dirname) is a binary! You are so correct! Thank you. Continuing; Correct. You could use different approaches which may or may not fail due to the directory names you will encounter (like directories with spaces or special characters). In this application, all the directories will be non-problematic, but point well taken. #!/bin/sh for DIR in `ls -LF | grep \/`; do cd ${DIR} # do stuff done That works perfectly. Again many thanks. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash Shell Scripting Question
On Thu, 20 Sep 2012 11:16:40 +0200, Jan Henrik Sylvester wrote: On 09/20/2012 04:29, Polytropon wrote: Correct. You could use different approaches which may or may not fail due to the directory names you will encounter (like directories with spaces or special characters). #!/bin/sh for DIR in `ls -LF | grep \/`; do cd ${DIR} # do stuff done Or you can use piping: #!/bin/sh ls -LF | grep \/ | while read DIR; do cd ${DIR} # do stuff done I'm quite confident there are even more elegant and fault- tolerant solutions. You would maybe have to tweak the ls command or play with IFS (space or newline). Even if you start quoting ${DIR}, the first one will fail at least for names containing spaces, the second one at least for names starting with spaces. As you said, you would have to change IFS to maybe slash and newline, assuming that you do not have names containing newlines, in which case the approach cannot work. You are fully correct: In order to create an iterator that provides valid directory names, even for the cases where unusual characters (which are _valid_ characters for file names and directory names) are included, is not trivial. Allow me to point to those two articles which mention different approaches and show why they are wrong. :-) David A. Wheeler: Filenames and Pathnames in Shell: How to do it correctly http://www.dwheeler.com/essays/filenames-in-shell.html David A. Wheeler: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html I understand that you want all directories and links to directories not starting with a period. How about trying all files not starting with a period and skipping the non directories: #!/bin/sh for DIR in * do cd $DIR /dev/null 21 || continue pwd cd - /dev/null done This one works with names containing spaces or even newlines and does not even need to spawn external commands or subshells. It may have other caveats, though. It will work - it delegates resolving * to the shell instead of having a different program (ls | grep, find) doing that. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
bash Shell Scripting Question
I just discovered a knowledge deficiency on my part that I can't seem to resolve. If one writes a loop of the following form: #!/usr/local/bin/bash ls -LF |grep \/ /tmp/files while read dirname; do cd $dirname #Do whatever commands to be repeated in each directory. done /tmp/files This works quite well but it is shall we say sloppy because it creates a file that then must be cleaned up and its name needs to be made unique, etc. The standard output of the `ls -LF |grep \/` command needs to look like a file and all should be well. I thought the redirection would pickup the standard output. Thanks for ideas. Martin McCormick ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash Shell Scripting Question
On Wed, 19 Sep 2012 21:03:11 -0500 Martin McCormick wrote: #!/usr/local/bin/bash ls -LF |grep \/ /tmp/files while read dirname; do cd $dirname #Do whatever commands to be repeated in each directory. done /tmp/files How about: ls -LF | grep \/ | while read dirname; do cd $dirname # do stuff done or: find . -maxdepth 1 -type d | while read dirname; do cd $dirname # do stuff done or even: find . -maxdepth 1 -type d ! -name .* | while read dirname; do cd $dirname # do stuff done -- Mihai Donțu ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash Shell Scripting Question
On Wed, 19 Sep 2012 21:03:11 -0500, Martin McCormick wrote: I just discovered a knowledge deficiency on my part that I can't seem to resolve. If one writes a loop of the following form: #!/usr/local/bin/bash Just a sidenote: If you're not using bash-specific functionality and intend to make your script portable, use #!/bin/sh instead. ls -LF |grep \/ /tmp/files while read dirname; do Attention: dirname (/usr/bin/dirname) is a binary! cd $dirname #Do whatever commands to be repeated in each directory. done /tmp/files This works quite well but it is shall we say sloppy because it creates a file that then must be cleaned up and its name needs to be made unique, etc. Correct. You could use different approaches which may or may not fail due to the directory names you will encounter (like directories with spaces or special characters). #!/bin/sh for DIR in `ls -LF | grep \/`; do cd ${DIR} # do stuff done Or you can use piping: #!/bin/sh ls -LF | grep \/ | while read DIR; do cd ${DIR} # do stuff done I'm quite confident there are even more elegant and fault- tolerant solutions. You would maybe have to tweak the ls command or play with IFS (space or newline). The standard output of the `ls -LF |grep \/` command needs to look like a file and all should be well. I thought the redirection would pickup the standard output. No, the and redirections basically operate on files, while pipes redirect strandard output to standard input. So for example, somecommand /tmp/somefile refers to a file that has to exist, while somecommand `someothercommand` does not take someothercommand's output (stdout), but instead interprets it as a file specification and then reads from that files (if existing). -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
A bash scripting question
How Can I simplify/perfect the following script, so that I read _ALL_ the lines in the file and act on the content as shown below, so that I do not have to specifiy an action per line? This below is doing exactly what i need BUT reading one line at a time untill the 10th line, if i want more i add manually... This might help some1 someday! But if there is a way to perfect it please do so. #!/usr/local/bin/bash smsfile=email_to_sms `grep Subject /var/spool/mail/sms $smsfile` if [[ -s $smsfile ]] ; then cat /dev/null /var/spool/mail/sms sed -i 's/Subject: //g' $smsfile echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 {print $1}' $smsfile` echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 {print $1}' $smsfile` echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 {print $1}' $smsfile` echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 {print $1}' $smsfile` echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 {print $1}' $smsfile` echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 {print $1}' $smsfile` echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 {print $1}' $smsfile` echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 {print $1}' $smsfile` echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 {print $1}' $smsfile` echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 {print $1}' $smsfile` else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat email_to_sms email_to_sms2 cat /dev/null email_to_sms -- Best regards, Odhiambo WASHINGTON, Nairobi,KE +254733744121/+254722743223 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I can't hear you -- I'm using the scrambler. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: A bash scripting question
On Jun 21, 2012, at 6:40 AM, Odhiambo Washington wrote: How Can I simplify/perfect the following script, so that I read _ALL_ the lines in the file and act on the content as shown below, so that I do not have to specifiy an action per line? This below is doing exactly what i need BUT reading one line at a time untill the 10th line, if i want more i add manually... This might help some1 someday! But if there is a way to perfect it please do so. #!/usr/local/bin/bash smsfile=email_to_sms `grep Subject /var/spool/mail/sms $smsfile` if [[ -s $smsfile ]] ; then cat /dev/null /var/spool/mail/sms sed -i 's/Subject: //g' $smsfile echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 {print $1}' $smsfile` echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 {print $1}' $smsfile` echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 {print $1}' $smsfile` echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 {print $1}' $smsfile` echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 {print $1}' $smsfile` echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 {print $1}' $smsfile` echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 {print $1}' $smsfile` echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 {print $1}' $smsfile` echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 {print $1}' $smsfile` echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 {print $1}' $smsfile` else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat email_to_sms email_to_sms2 cat /dev/null email_to_sms Try the following… #!/bin/sh smsfile=email_to_sms spoolfile=/var/spol/mail/sms grep Subject $spoolfile $smsfile if [ -s $smsfile ]; then : $spoolfile sed -e 's/Subject: //g' $smsfile | awk ' { if (NR 10) exit print | /usr/bin/gammu --sendsms TEXT $1 }' else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat $smsfile email_to_sms2 : $smsfile -- Devin _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: A bash scripting question
On 06/21/2012 08:40 AM, Odhiambo Washington wrote: How Can I simplify/perfect the following script, so that I read _ALL_ the lines in the file and act on the content as shown below, so that I do not have to specifiy an action per line? This below is doing exactly what i need BUT reading one line at a time untill the 10th line, if i want more i add manually... This might help some1 someday! But if there is a way to perfect it please do so. #!/usr/local/bin/bash smsfile=email_to_sms `grep Subject /var/spool/mail/sms $smsfile` if [[ -s $smsfile ]] ; then cat /dev/null /var/spool/mail/sms sed -i 's/Subject: //g' $smsfile echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 {print $1}' $smsfile` echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 {print $1}' $smsfile` echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 {print $1}' $smsfile` echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 {print $1}' $smsfile` echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 {print $1}' $smsfile` echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 {print $1}' $smsfile` echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 {print $1}' $smsfile` echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 {print $1}' $smsfile` echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 {print $1}' $smsfile` echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 {print $1}' $smsfile` else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat email_to_sms email_to_sms2 cat /dev/null email_to_sms Off the top of my head: 8 #!/bin/sh -e sed -e '/^Subject: /!d; s/^Subject: //' /var/spool/mail/sms ${smsfile} :/var/spool/mail/sms xargs -L1 /usr/bin/gammu --sendsms TEXT ${smsfile} mv -f ${smsfile} ${smsfile}.bak 8 No loops necessary. By the way, what's gammu, and why is it in /usr/bin ? -- Fuzzy love, -CyberLeo Technical Administrator CyberLeo.Net Webhosting http://www.CyberLeo.Net cyber...@cyberleo.net Furry Peace! - http://.fur.com/peace/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: A bash scripting question
CyberLeo Kitsana wrote Odhiambo Washington: By the way, what's gammu, /usr/ports/comms/gammu presumably ( for mobile phone connection ) and why is it in /usr/bin ? Pass. Cheers, Julian -- Julian Stacey, BSD Unix Linux C Sys Eng Consultants Munich http://berklix.com Reply below not above, cumulative like a play script, indent with . Format: Plain text. Not HTML, multipart/alternative, base64, quoted-printable. Mail from @yahoo dumped @berklix. http://berklix.org/yahoo/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: A bash scripting question
-Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of Devin Teske Sent: Thursday, June 21, 2012 9:24 AM To: Odhiambo Washington Cc: questions Subject: Re: A bash scripting question On Jun 21, 2012, at 6:40 AM, Odhiambo Washington wrote: How Can I simplify/perfect the following script, so that I read _ALL_ the lines in the file and act on the content as shown below, so that I do not have to specifiy an action per line? This below is doing exactly what i need BUT reading one line at a time untill the 10th line, if i want more i add manually... This might help some1 someday! But if there is a way to perfect it please do so. #!/usr/local/bin/bash smsfile=email_to_sms `grep Subject /var/spool/mail/sms $smsfile` if [[ -s $smsfile ]] ; then cat /dev/null /var/spool/mail/sms sed -i 's/Subject: //g' $smsfile echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 {print $1}' $smsfile` echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 {print $1}' $smsfile` echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 {print $1}' $smsfile` echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 {print $1}' $smsfile` echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 {print $1}' $smsfile` echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 {print $1}' $smsfile` echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 {print $1}' $smsfile` echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 {print $1}' $smsfile` echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 {print $1}' $smsfile` echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 {print $1}' $smsfile` else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat email_to_sms email_to_sms2 cat /dev/null email_to_sms Try the following. #!/bin/sh smsfile=email_to_sms spoolfile=/var/spol/mail/sms grep Subject $spoolfile $smsfile if [ -s $smsfile ]; then : $spoolfile sed -e 's/Subject: //g' $smsfile | awk ' { if (NR 10) exit print | /usr/bin/gammu --sendsms TEXT $1 }' else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat $smsfile email_to_sms2 : $smsfile I can beat my original response (above), while retaining original functionality... #!/bin/sh spoolfile=/var/spool/mail/sms awk -v pat=^Subject: ' $0 ~ pat { sub(pat,) print | /usr/bin/gammu --sendsms TEXT $1 }' $spoolfile Or, as a shell One-Liner (compatible with any shell and any awk)... awk -v pat=^Subject: '$0~pat{sub(pat,);print|/usr/bin/gammu --sendsms TEXT $1}' $spoolfile -- Devin _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: A bash scripting question
-Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of dte...@freebsd.org Sent: Thursday, June 21, 2012 12:57 PM To: 'Odhiambo Washington' Cc: 'questions' Subject: RE: A bash scripting question -Original Message- From: owner-freebsd-questi...@freebsd.org [mailto:owner-freebsd- questi...@freebsd.org] On Behalf Of Devin Teske Sent: Thursday, June 21, 2012 9:24 AM To: Odhiambo Washington Cc: questions Subject: Re: A bash scripting question On Jun 21, 2012, at 6:40 AM, Odhiambo Washington wrote: How Can I simplify/perfect the following script, so that I read _ALL_ the lines in the file and act on the content as shown below, so that I do not have to specifiy an action per line? This below is doing exactly what i need BUT reading one line at a time untill the 10th line, if i want more i add manually... This might help some1 someday! But if there is a way to perfect it please do so. #!/usr/local/bin/bash smsfile=email_to_sms `grep Subject /var/spool/mail/sms $smsfile` if [[ -s $smsfile ]] ; then cat /dev/null /var/spool/mail/sms sed -i 's/Subject: //g' $smsfile echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 {print $1}' $smsfile` echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 {print $1}' $smsfile` echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 {print $1}' $smsfile` echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 {print $1}' $smsfile` echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 {print $1}' $smsfile` echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 {print $1}' $smsfile` echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 {print $1}' $smsfile` echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 {print $1}' $smsfile` echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 {print $1}' $smsfile` echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 {print $1}' $smsfile` else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat email_to_sms email_to_sms2 cat /dev/null email_to_sms Try the following. #!/bin/sh smsfile=email_to_sms spoolfile=/var/spol/mail/sms grep Subject $spoolfile $smsfile if [ -s $smsfile ]; then : $spoolfile sed -e 's/Subject: //g' $smsfile | awk ' { if (NR 10) exit print | /usr/bin/gammu --sendsms TEXT $1 }' else echo ***Sorry the SMS FILE $smsfile is empty. fi gammu-smsd start cat $smsfile email_to_sms2 : $smsfile I can beat my original response (above), while retaining original functionality... #!/bin/sh spoolfile=/var/spool/mail/sms awk -v pat=^Subject: ' $0 ~ pat { sub(pat,) print | /usr/bin/gammu --sendsms TEXT $1 }' $spoolfile Actually, some functionality was lost in the above translation, let me add the missing functionality back-in... #!/bin/sh spoolfile=/var/spool/mail/sms awk -v pat=^Subject: ' BEGIN { found = 0 } $0 ~ pat { found++ sub(pat, ) print | /usr/bin/gammu --sendsms TEXT $1 } END { if ( ! found ) printf %sSorry the SMS FILE \%s\ is empty.%s\n, ***, FILENAME, *** exit ! found }' $spoolfile : $spoolfile Or, as a shell One-Liner (compatible with any shell and any awk)... The above doesn't translate so-well into a one-liner (unless you can stomach really long lines 80 chars), but here it is... awk -v pat=^Subject: 'BEGIN{found=0}$0~pat{found++;sub(pat, );print|/usr/bin/gammu --sendsms TEXT $1}END{if(!found)printf %sSorry the SMS FILE \%s\ is empty.%s\n,***,FILENAME,***;exit !found}' /var/spool/mail/sms : /var/spool/mail/sms -- Devin P.S. I think the above is the best you can do. _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
You know St. Peter won't call my name, freebsd-questions! 2011/01/03 20:23:38 -0800 Joseph Olatt j...@eskimo.com = To Frank Shute : JO On Sun, Dec 26, 2010 at 05:09:30PM +, Frank Shute wrote: JO JO I generally play my tracks of an album like so: JO JO for track in $(cat trombone_shorty-backatown.m3u); do JO mplayer $track JO done JO JO They then play in the correct order. JO JO How would I go about randomising the order of play using JO sh (preferably) or perl? I have several tens of thousands of MIDI files from 90s. They are too many for 'random play' feature of the Timidity++ which is used with 'eawpats', the GUS patches. Here is my bash script to play them in random order: === #!/usr/local/bin/bash IFS=' ' fns=(`find ~/mid/ -iname '*.mid'`) while :; do timidity -a -OdS -in -j -t 1251 -E t -p a -R 500 -EFreverb=127 -EFns=4 ${fns[$((${#f...@]}*$random/32767))]} done === Of course I miss the 'Previous track' functionality. 73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB 12F8 0CE1 4AAC A0E2 6627) -- http://vereshagin.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 05:09:30PM +, Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html A little while back I wrote a perl script to randomly pick mp3, ogg, flac files from any directory specified as arg 1 and play them using mplayer. I categorize my genres by directory and with this perl script I can randomly play songs from any directory. If the script is invoked without any arguments, then it will play songs from the default hard-coded directory defined by $SONG_DIR. Don't know if this would be useful to you (or someone else). #!/usr/bin/perl -w use strict; my $SONG_DIR = /home/joji/songs/good; if ($#ARGV == 0) { $SONG_DIR = $ARGV[0]; } my %played = (); my $rand; my $dh; my @song_list; opendir($dh, $SONG_DIR); @song_list = readdir($dh); closedir($dh); my $count = $#song_list; # Perl counts from zero. If there is one item, Perl will say 0. # So to get the real count, we have to increment by 1. $count++; chdir($SONG_DIR); while ((keys %played) $count) { while (1) { $rand = int(rand($count)); if (! $played{$rand}) { $played{$rand} = 1; last; } if ((keys %played) = $count) { last; } } if ($song_list[$rand] eq . || $song_list[$rand] eq ..) { ; } else { print Playing song # . $rand . [ . $song_list[$rand] . ]\n; `mplayer \$song_list[$rand]\`; } } exit(0); ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
randomising tracks: scripting question
I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org change cat t...n.m3u to random t..n.m3u -- Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com| http://chipsquips.com pgpvxO07hLh2G.pgp Description: PGP signature
Re: randomising tracks: scripting question
On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
How would I go about randomising the order of play using sh (preferably) or perl? I fiddled around for a minute without luck but I think between the built-in $RANDOM, tail and head you should be able to get a randomize going. I'd recommend putting a script together that just pulls a random line from a file then work from there. Post your results if yo get one working. -- # Mark Caudill ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 06:01:45PM +, RW wrote: On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) Excellent. I didn't know about random(6), I was getting lost in the manpages: there are manpages for random in 3 different sections! Should have used apropos. Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? cat trombone_shorty-backatown.m3u | xargs mplayer ... -shuffle or mplayer ... -playlist trombone_shorty-backatown.m3u -shuffle if they are in a uncommented, one-absolute-path-per-line format without extended directives? b. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Sun, Dec 26, 2010 at 2:04 PM, b. f. bf1...@googlemail.com wrote: Frank Shute wrote: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? cat trombone_shorty-backatown.m3u | xargs mplayer ... -shuffle or mplayer ... -playlist trombone_shorty-backatown.m3u -shuffle if they are in a uncommented, one-absolute-path-per-line format without extended directives? Here is something that I wrote a long time ago in python, works quite well [code] #!/usr/bin/env python def randline(f): for i,j in enumerate(file(f, 'rb')): if random.randint(0,i) == i: line = j eturn line print randline(text) [/code] Name it as you wish then it's ./file.py INPUT, granted this will only read 1 (random) line from INPUT and print it, it shouldn't be hard to modify this for your needs tho, enjoy :) C- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: randomising tracks: scripting question
On Dec 26, 2010, at 11:02 AM, Frank Shute wrote: On Sun, Dec 26, 2010 at 06:01:45PM +, RW wrote: On Sun, 26 Dec 2010 09:40:43 -0800 Chip Camden sterl...@camdensoftware.com wrote: Quoth Frank Shute on Sunday, 26 December 2010: I generally play my tracks of an album like so: for track in $(cat trombone_shorty-backatown.m3u); do mplayer $track done They then play in the correct order. How would I go about randomising the order of play using sh (preferably) or perl? Sorry for the OT posting but I thought a brainteaser might clear the fog caused by excessive Xmas indulgence ;) Regards, change cat t...n.m3u to random t..n.m3u That should be random -f trombone_shorty-backatown.m3u see random(6) for what happens when it reads directly from stdin (without -f -) Excellent. I didn't know about random(6), I was getting lost in the manpages: there are manpages for random in 3 different sections! Should have used apropos. Just keep in mind that random(6) comes from the `games' distribution-set. wget -r ftp://ftp-archive.freebsd.org/pub/FreeBSD/releases/i386/8.1-RELEASE/games cd games sudo ./install.sh Not sure if it's available anywhere else. -- Devin ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
Nerius Landys nlan...@gmail.com wrote: Is there a function, or command line utility, to escape a string, making it suitable to be input on the command line? For example, this escape utility would take a input of te st and create an output of te\ st. Other things such as quotes and single quotes would be handled as well. You can use something like this: sed 's/[^A-Za-z_0-9]/\\/' Perl has a quotemeta() function and \Q escape sequence for this purpose, e.g.: $ perl -e '$_=te st; print \Q$_\E\n' te\ st -- Christian naddy Weisgerber na...@mips.inka.de ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
On 15.02.2010 09:21, Nerius Landys wrote: But in the case where you're assigning the output of ls directly to a variable like this: FOO=`ls` vs FOO=`ls` the text assigned to FOO is the same, right? Apparently, it is: sh-4.0$ touch x * sh-4.0$ FOO=`ls`;echo $FOO|od 000 020170 005052 004 sh-4.0$ BAR=`ls`; echo $BAR|od 000 020170 005052 004 There might be some corner cases tho. Test before puting into production (newlines/control chars in file names, different versions of shell, different set/shopt options, changes in IFS etc). -- Eray ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
Nerius Landys nlan...@gmail.com wrote: #!/bin/sh DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` What if I got rid of extra double quotes? Like this: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` That is perfectly fine. Word-splitting and filename expansion are not performed for variable assignments. Also immune is the expression after case, so this is always fine: case $FOO in ... -- Christian naddy Weisgerber na...@mips.inka.de ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
#!/bin/sh DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` What if I got rid of extra double quotes? Like this: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` That is perfectly fine. Word-splitting and filename expansion are not performed for variable assignments. Also immune is the expression after case, so this is always fine: case $FOO in ... Since you guys have been so helpful I thought I'd ask one more question. Let's say I have a script named te st (yes, with a space in the filename). The contents of this script are: #!/bin/sh if [ $# -ne 2 ]; then echo 12 One argument expected. Example usage: echo 12 `basename \${0}\` 64.156.192.169 cheaters exit 1 fi When executed with no arguments, this script would print something like so: nlan...@daffyzsh# ./te\ st One argument expected. Example usage: te st 64.156.192.169 cheaters nlan...@daffyzsh# Is there a function, or command line utility, to escape a string, making it suitable to be input on the command line? For example, this escape utility would take a input of te st and create an output of te\ st. Other things such as quotes and single quotes would be handled as well. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
simple (and stupid) shell scripting question
#!/bin/sh I have these lines in my script: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` What if I got rid of extra double quotes? Like this: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` Does this behave any differently in any kind of case? Are thes double quotes just superfluous? ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
On 15.02.2010 08:07, Nerius Landys wrote: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` What if I got rid of extra double quotes? Like this: DIRNAME=`dirname \$0\` cd $DIRNAME SCRIPTDIR=`pwd` Does this behave any differently in any kind of case? Are thes double quotes just superfluous? From the man page: Command Substitution [...] If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results. In other words: sh-4.0$ touch x y sh-4.0$ for i in `ls`; do echo $i; done x y sh-4.0$ for i in `ls`; do echo $i; done x y sh-4.0$ -- Eray ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: simple (and stupid) shell scripting question
From the man page: Command Substitution [...] If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results. In other words: sh-4.0$ touch x y sh-4.0$ for i in `ls`; do echo $i; done x y sh-4.0$ for i in `ls`; do echo $i; done x y sh-4.0$ But in the case where you're assigning the output of ls directly to a variable like this: FOO=`ls` vs FOO=`ls` the text assigned to FOO is the same, right? I know that later if you do for f in $FOO; do done it's different from for f in $FOO; do done that much is clear. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Shell scripting question - incrementing
Paul Schmehl wrote: I could do this in perl easily, but I'm trying to force myself to learn shell scripting better. :-) ... Once this file is created (or ideally *while* it's being created!) I need to increment the sid numbers. The first one is 201. The second needs to be 202, and so forth. I don't know the total number of lines ahead of time, but it's easy enough to get after the file is created. (wc -l file.rules | awk '{print $1}') Is there a way to do this in shell scripting? In perl I'd use a for loop and vars, but I'm not sure how to solve this problem in shell scripting. You can do simple integer arithmetics using expr. You'll have to realize this in a while loop: i=201 while [ $i -le $largest_i ]; do # insert code here i=`expr $i + 1` done ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Shell scripting question - incrementing
I could do this in perl easily, but I'm trying to force myself to learn shell scripting better. :-) I'm parsing a file to extract some elements from it, then writing the results, embeded in long strings, into an output file. Here's the script: cat file.1 | cut -d',' -f9 | sort | uniq file.nicks (read line; echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); while read line; do echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); done) file.nicks file.rules The result is a file with a bunch of snort rules in it (I can't provide the actual data because it's sensitive.) The rules look like this: alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel detected; classtype:trojan-activity; content:JOIN; content:channel; sid:201; rev:1;) alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel2 detected; classtype:trojan-activity; content:JOIN; content:channel2; sid:201; rev:1;) Once this file is created (or ideally *while* it's being created!) I need to increment the sid numbers. The first one is 201. The second needs to be 202, and so forth. I don't know the total number of lines ahead of time, but it's easy enough to get after the file is created. (wc -l file.rules | awk '{print $1}') Is there a way to do this in shell scripting? In perl I'd use a for loop and vars, but I'm not sure how to solve this problem in shell scripting. In pseudo code I would do: COUNT=`wc -l file.rules | awk '{print $1}'` LAST_SID=$((200 + COUNT)) for (i=201; i = ${LAST_SID}; i++) { sed 's/201/${i}/g file.rules rules.new' } -- Paul Schmehl ([EMAIL PROTECTED]) Senior Information Security Analyst The University of Texas at Dallas http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question - incrementing
At 11:35 AM 2/19/2008, Paul Schmehl wrote: I could do this in perl easily, but I'm trying to force myself to learn shell scripting better. :-) I'm parsing a file to extract some elements from it, then writing the results, embeded in long strings, into an output file. Here's the script: cat file.1 | cut -d',' -f9 | sort | uniq file.nicks (read line; echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); while read line; do echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); done) file.nicks file.rules The result is a file with a bunch of snort rules in it (I can't provide the actual data because it's sensitive.) The rules look like this: alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel detected; classtype:trojan-activity; content:JOIN; content:channel; sid:201; rev:1;) alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel2 detected; classtype:trojan-activity; content:JOIN; content:channel2; sid:201; rev:1;) Once this file is created (or ideally *while* it's being created!) I need to increment the sid numbers. The first one is 201. The second needs to be 202, and so forth. I don't know the total number of lines ahead of time, but it's easy enough to get after the file is created. (wc -l file.rules | awk '{print $1}') Is there a way to do this in shell scripting? In perl I'd use a for loop and vars, but I'm not sure how to solve this problem in shell scripting. In pseudo code I would do: COUNT=`wc -l file.rules | awk '{print $1}'` LAST_SID=$((200 + COUNT)) for (i=201; i = ${LAST_SID}; i++) { sed 's/201/${i}/g file.rules rules.new' } Similar to what other's have offered: for i in `cat file.rules`;do sed 's/201/${i}/g rules.new; done -Derek -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question - incrementing
Paul Schmehl wrote: I could do this in perl easily, but I'm trying to force myself to learn shell scripting better. :-) I'm parsing a file to extract some elements from it, then writing the results, embeded in long strings, into an output file. Here's the script: cat file.1 | cut -d',' -f9 | sort | uniq file.nicks (read line; echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); while read line; do echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (msg:\JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; sid:201; rev:1;); done) file.nicks file.rules The result is a file with a bunch of snort rules in it (I can't provide the actual data because it's sensitive.) The rules look like this: alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel detected; classtype:trojan-activity; content:JOIN; content:channel; sid:201; rev:1;) alert ip $HOME_NET any - $EXTERNAL_NET any (msg:JOIN channel2 detected; classtype:trojan-activity; content:JOIN; content:channel2; sid:201; rev:1;) Once this file is created (or ideally *while* it's being created!) I need to increment the sid numbers. The first one is 201. The second needs to be 202, and so forth. I don't know the total number of lines ahead of time, but it's easy enough to get after the file is created. (wc -l file.rules | awk '{print $1}') Is there a way to do this in shell scripting? In perl I'd use a for loop and vars, but I'm not sure how to solve this problem in shell scripting. In pseudo code I would do: COUNT=`wc -l file.rules | awk '{print $1}'` LAST_SID=$((200 + COUNT)) for (i=201; i = ${LAST_SID}; i++) { sed 's/201/${i}/g file.rules rules.new' } for i in `jot $COUNT 201`; do # foo bar done -- Pietro Cerutti PGP Public Key: http://gahr.ch/pgp signature.asc Description: OpenPGP digital signature
Re: Shell scripting question - incrementing
--On Tuesday, February 19, 2008 12:41:43 -0600 Derek Ragona [EMAIL PROTECTED] wrote: Thanks to all who offered suggestions. Here's a working script that creates snort rules *and* a sid-msg.map file: #!/bin/sh cat file.1 | cut -d',' -f9 | sort | uniq file.nicks i=202 j=`wc -l file.nicks | awk '{print $1}'` k=$(( i + j - 1 )) (read line; echo alert ip \$HOME_NET any - \$EXTERNAL_NET any ( sid:201; msg:\ JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; rev:1;); while read line [ $i -le $k ]; do echo alert ip \$HOME_NET any - \$EXTERNAL_NET any (sid:$i; msg:\ JOIN $line detected\; classtype:trojan-activity; content:\JOIN\; content:$line; rev:1;); i=`expr $i + 1`; done) file.nicks file.rules cat file.rules | cut -d':' -f2,3 | cut -d';' -f1,2 | sed 's/; msg:/ || /g' file-sid-msg.map -- Paul Schmehl ([EMAIL PROTECTED]) Senior Information Security Analyst The University of Texas at Dallas http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Thursday 13 September 2007 20:35, Roland Smith wrote: On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. [snip] I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. I don't have the perl skills, though that would be ideal. Any help out there? #!/usr/bin/perl while () { # Assuming no whitespace in addresses; kill everything after the first # space s/ .*$//; # Store the name count in a hash $names{$_}++; } # Go over the hash while (($name,$count) = each(%names)) { if ($count == 1) { # print unique names. print $name, \n; } } Another approach in Perl would be: #!/usr/bin/perl my (%names, %dups); while () { my ($key) = split; $dups{$key} = 1 if $names{$key}; $names{$key} = 1; } delete @names{keys %dups}; # # keys %names is now an unordered list of only non-repeated elements # keys %dups is an unordered list of only repeated elements split splits on whitespace, returning a list of fields which can be assigned to a list of variables. Here we only want to capture the first field: split is more efficient for this than using a regex. The first occurrence of $key is in parens because it's actually a list of one variable name. We build two hashes, one, %name, keyed by the original names (this is the classic way to reduce duplicates to single occurrences, since the duplicated keys overwrite the originals), and one, %dup, whose keys are names already appearing in %names - the duplicated entries. Having done that we use a hash slice to delete from %names all the keys of %dups, which leaves the keys of %names holding all the entries which only appear once (and the keys of %dups all the duplicated entries if that's useful). Jonathan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
I don't have the perl skills, though that would be ideal. -- snip -- Another approach in Perl would be: #!/usr/bin/perl my (%names, %dups); while () { my ($key) = split; $dups{$key} = 1 if $names{$key}; $names{$key} = 1; } delete @names{keys %dups}; # # keys %names is now an unordered list of only non-repeated elements # keys %dups is an unordered list of only repeated elements split splits on whitespace, returning a list of fields which can be assigned to a list of variables. Here we only want to capture the first field: split is more efficient for this than using a regex. The first occurrence of $key is in parens because it's actually a list of one variable name. We build two hashes, one, %name, keyed by the original names (this is the classic way to reduce duplicates to single occurrences, since the duplicated keys overwrite the originals), and one, %dup, whose keys are names already appearing in %names - the duplicated entries. Having done that we use a hash slice to delete from %names all the keys of %dups, which leaves the keys of %names holding all the entries which only appear once (and the keys of %dups all the duplicated entries if that's useful). I don't know if this is completely relevant, but it appears as though it may help. Bob Showalter once advised me on the Perl Beginners list as such, quoted, but snipped for clarity: see perldoc -q duplicate If the array elements can be compared with string semantics (as you are doing here), the following will work: my @array = do { my %seen; grep !$seen{$_}++, @clean }; Steve ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Friday 14 September 2007 09:42, Steve Bertrand wrote: I don't have the perl skills, though that would be ideal. -- snip -- Another approach in Perl would be: #!/usr/bin/perl my (%names, %dups); while () { my ($key) = split; $dups{$key} = 1 if $names{$key}; $names{$key} = 1; } delete @names{keys %dups}; I don't know if this is completely relevant, but it appears as though it may help. Bob Showalter once advised me on the Perl Beginners list as such, quoted, but snipped for clarity: see perldoc -q duplicate If the array elements can be compared with string semantics (as you are doing here), the following will work: my @array = do { my %seen; grep !$seen{$_}++, @clean }; The problem with this is that it leaves you with one copy of each duplicated item: the requirement was to remove all copies of duplicated items and return only the non-repeated items. Jonathan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Scripting question
I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. I don't have the perl skills, though that would be ideal. Any help out there? Kurt ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. Seems like this is right up sort's alley. Is the first string always separated from the rest by white space or does your first string sometimes include white space. jerry I don't have the perl skills, though that would be ideal. Any help out there? Kurt ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
First, please always make sure your responses go to the list. It is both list etiquette and of practical value. Follow-ups to only an individual may not reach the person who can provide real help. Most Email clients have a group reply which will do the trick. On Thu, Sep 13, 2007 at 10:32:34AM -0700, Kurt Buff wrote: On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. Seems like this is right up sort's alley. Is the first string always separated from the rest by white space or does your first string sometimes include white space. jerry The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. jerry ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. jerry Ya know, it's really easy to get wrapped around the axle on this stuff. I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. Sigh. Kurt ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: First, please always make sure your responses go to the list. It is both list etiquette and of practical value. Follow-ups to only an individual may not reach the person who can provide real help. Most Email clients have a group reply which will do the trick. Yup - that's my fault, and contrary to my intent - I was using the web interface, and it's too easy to just hit the reply button instead of reply to all - mea culpa. On Thu, Sep 13, 2007 at 10:32:34AM -0700, Kurt Buff wrote: On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. Seems like this is right up sort's alley. Is the first string always separated from the rest by white space or does your first string sometimes include white space. jerry The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. Tried that, and it doesn't work the way I expect, or else I'm doing it wrong, which is definitely possible. My first difficulty is that I can't figure out how to specify the space as the field delimiter, assuming that -t is the correct parameter for that. I've tried specifying '@' for -t, but that doesn't work either. Next, my suspicion is that the -u parameter will simply output the first line of a set of non-unique lines, which is what it does normally - it doesn't seem to eliminate all non-unique lines, it just makes the first line the unique one. Am I making sense? Kurt ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. I don't have the perl skills, though that would be ideal. Any help out there? #!/usr/bin/perl while () { # Assuming no whitespace in addresses; kill everything after the first space s/ .*$//; # Store the name count in a hash $names{$_}++; } # Go over the hash while (($name,$count) = each(%names)) { if ($count == 1) { # print unique names. print $name, \n; } } Roland -- R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725) pgpjohzJDWDRW.pgp Description: PGP signature
Re: Scripting question
On Sep 13, 2007, at 1:19 PM, Kurt Buff wrote: I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. Instead of grep -v take a look at comm. -j ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. jerry Ya know, it's really easy to get wrapped around the axle on this stuff. I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. Sigh. Kurt It sounds like you've found your solution, but how about the below shell script? Probably woefully inefficient, but should work. - Craig ### begin script ## #!/bin/sh # Read in an input list of 2 column data pairs and output the pairs where the first columns are unique. INPUT_FILE=list.txt OUTPUT_FILE=new_list.txt NON_UNIQ_LIST= for NON_UNIQ in `cat $INPUT_FILE | awk '{print $1}' | sort | uniq -c | grep -vE '^ *1' | awk '{print $2}'` do NON_UNIQ_LIST=$NON_UNIQ_LIST|$NON_UNIQ done NON_UNIQ_LIST=`echo $NON_UNIQ_LIST | sed 's/^.//'` cat $INPUT_FILE | grep -vE $NON_UNIQ_LIST $OUTPUT_FILE ### end script ## ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Roland Smith [EMAIL PROTECTED] wrote: On Thu, Sep 13, 2007 at 10:16:40AM -0700, Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. I've got a sorted file of SMTP addresses, and want to eliminate the lines that are the same up to a space character within the line. Example: [EMAIL PROTECTED] NO [EMAIL PROTECTED] OK The above lines *both* need to be eliminated from output - I don't want the first or second of them, I want them both gone. I've looked at sort and uniq, and I've googled a fair bit but can't seem to find anything that would do this. I don't have the perl skills, though that would be ideal. Any help out there? #!/usr/bin/perl while () { # Assuming no whitespace in addresses; kill everything after the first space s/ .*$//; # Store the name count in a hash $names{$_}++; } # Go over the hash while (($name,$count) = each(%names)) { if ($count == 1) { # print unique names. print $name, \n; } } Roland -- R.F.Smith http://www.xs4all.nl/~rsmith/ [plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated] pgp: 1A2B 477F 9970 BA3C 2914 B7CE 1277 EFB0 C321 A725 (KeyID: C321A725) I can follow the logic in that. I'll definitely try incorporating that. Thanks! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Craig Whipp [EMAIL PROTECTED] wrote: On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. jerry Ya know, it's really easy to get wrapped around the axle on this stuff. I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. Sigh. Kurt It sounds like you've found your solution, but how about the below shell script? Probably woefully inefficient, but should work. - Craig ### begin script ## #!/bin/sh # Read in an input list of 2 column data pairs and output the pairs where the first columns are unique. INPUT_FILE=list.txt OUTPUT_FILE=new_list.txt NON_UNIQ_LIST= for NON_UNIQ in `cat $INPUT_FILE | awk '{print $1}' | sort | uniq -c | grep -vE '^ *1' | awk '{print $2}'` do NON_UNIQ_LIST=$NON_UNIQ_LIST|$NON_UNIQ done NON_UNIQ_LIST=`echo $NON_UNIQ_LIST | sed 's/^.//'` cat $INPUT_FILE | grep -vE $NON_UNIQ_LIST $OUTPUT_FILE ### end script ## I'll fiddle with this too, but I like the perl better. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On 9/13/07, Jeffrey Goldberg [EMAIL PROTECTED] wrote: On Sep 13, 2007, at 1:19 PM, Kurt Buff wrote: I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. Instead of grep -v take a look at comm. -j Interesting! I just looked at the man page, and while I don't think it it's going to be directly useful (or I'm just not reading the page correctly), it's a new utility to me - I'll keep it in mind for other things. Thanks! ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Sep 13, 2007, at 2:38 PM, Kurt Buff wrote: Instead of grep -v take a look at comm. Interesting! I just looked at the man page, and while I don't think it it's going to be directly useful (or I'm just not reading the page correctly), it's a new utility to me - I'll keep it in mind for other things. Maybe I haven't understood what you are after. If you want to get lines that exist in either file1 or file2 but not both (and if the files are already sorted) then comm -3 file1 file2 will do that. -j -- Jeffrey Goldberghttp://www.goldmark.org/jeff/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Scripting question
On Thursday 13 September 2007 20:19, Kurt Buff wrote: On 9/13/07, Jerry McAllister [EMAIL PROTECTED] wrote: The only space is the one separating the SMTP address from the OK or NO. Then you should be able to tell it to sort on the first token in the string with white space as a separator and to eliminate duplicates. It has been a long time since I had need of sort. I don't remember the arguments/flags but am sure that type of thing can be done. You can use uniq if the file is already sorted (if not, put a sort at the start of the pipe) - after using awk to pick the first field: awk '{print $1}' inputfile | uniq -u Ya know, it's really easy to get wrapped around the axle on this stuff. I think I may have a better solution. The file I'm trying to massage has a predecessor - the non-unique lines are the result of a concatenation of two files. Silly me, it's better to 'grep -v' with the one file vs. the second rather than trying to merge, sort and further massage the result. The fix will be to use sed against the first file to remove the ' NO', thus providing a clean argument for grepping the other file. If it's two files and you want to select or reject common lines, look at comm(1) as another technique. Jonathan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Scripting question
Kurt Buff wrote: I'm trying to do some text file manipulation, and it's driving me nuts. ... I don't have the perl skills, though that would be ideal. Any help out there? Buy Learning Perl, Fourth Edition, read it, and do the exercises: http://www.oreilly.com/catalog/learnperl4/index.html Investing the effort to become proficient with Perl will serve you well in the long run. HTH, David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: mysqldump/gzip shell scripting question...
Eric Crist wrote: First off, I don't care if you send example in perl, php, or sh, but we're not a python shop here, so those recommendation will not be useful... I'm trying to write a shell script that scans our databases for tables starting with archive_ which are created by other scripts/departments, etc. This script needs to perform a mysqldump of that table, and then gzip it. It's MUCH quick to pipe directly to gzip, than perform the dump, then gzip that. The problem is, this table to filesystem dump is also going to drop those archive_* tables. We would like to know that the mysqldump worked before we do this. The problem we're having, as I'm sure others have run into (at least according to Google), is that a command such as the following leaves no apparent easy way to capture the exit status of the mysqldump command: # mysqldump -u $USER -p$PASS $DBHOST $DATABASE $TABLE | gzip $TABLE.sql.gz This rough perl should do the trick: open (MYSQL, /tmp/fail|) || die mysqldump failed; open (GZIP, |gzip /tmp/test.gz) || die gzip failed; while ($ret = read MYSQL, $buf, 4096) { print GZIP $buf || die gzip write failed: $!; } die gzip write failed: $! if (!defined($ret)); close(MYSQL) || die mysql close failed; close (GZIP) || die gzip close failed; and for testing /tmp/fail was executable and contained: #!/bin/sh - cat /etc/motd /etc/motd /etc/motd /etc/motd /etc/motd /etc/motd /etc/motd /etc/motd exit 1 With exit 1, perl dies on the MYSQL close, with exit 0 perl exits normally. If this works for you then /tmp/fail gets replaced with your mysqldump command and you'll need some params to pass in the name of the gzipped file. You can play with sysread instead of read, and vary the buffer size. No idea how it compares for speed to straight shell piping to gzip. hth, --Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
mysqldump/gzip shell scripting question...
Hey all, First off, I don't care if you send example in perl, php, or sh, but we're not a python shop here, so those recommendation will not be useful... I'm trying to write a shell script that scans our databases for tables starting with archive_ which are created by other scripts/ departments, etc. This script needs to perform a mysqldump of that table, and then gzip it. It's MUCH quick to pipe directly to gzip, than perform the dump, then gzip that. The problem is, this table to filesystem dump is also going to drop those archive_* tables. We would like to know that the mysqldump worked before we do this. The problem we're having, as I'm sure others have run into (at least according to Google), is that a command such as the following leaves no apparent easy way to capture the exit status of the mysqldump command: # mysqldump -u $USER -p$PASS $DBHOST $DATABASE $TABLE | gzip $TABLE.sql.gz Anyone have any good recommendations? Thanks! Eric Crist ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: mysqldump/gzip shell scripting question...
Eric Crist wrote: Hey all, First off, I don't care if you send example in perl, php, or sh, but we're not a python shop here, so those recommendation will not be useful... I'm trying to write a shell script that scans our databases for tables starting with archive_ which are created by other scripts/departments, etc. This script needs to perform a mysqldump of that table, and then gzip it. It's MUCH quick to pipe directly to gzip, than perform the dump, then gzip that. The problem is, this table to filesystem dump is also going to drop those archive_* tables. We would like to know that the mysqldump worked before we do this. The problem we're having, as I'm sure others have run into (at least according to Google), is that a command such as the following leaves no apparent easy way to capture the exit status of the mysqldump command: # mysqldump -u $USER -p$PASS $DBHOST $DATABASE $TABLE | gzip $TABLE.sql.gz Anyone have any good recommendations? Thanks! Eric Crist perldoc DBI if you want to access the database info directly from Perl (as opposed to mysqldump). Honestly, you're going to have to dig through some information in the API, and fish out the MySQL interfaces, but Perl or some other structured query API is probably a decent bet for what you want to do (unless you have a lot of data, in which I suggest using C equivalent methods or maybe Python if you want to stick with a scripting language), because it provides you with information and return statuses that straight mysqldump may not provide. Plus with Perl (at least) you could pipe file reading through an alternate method to ensure that things passed by searching the output for particular keys, etc. PHP also supports DB access methods though. Bourne/tcsh shell equivalent solutions would be kludgy and ill built for what you're trying to accomplish IMO. Cheers, -Garrett ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
stupid scripting question: zsh
Hello all, I've been upgrading my FreeBSD system into a fully-fledged desktop system. zsh as installed (from the port) seems only to recognize the /etc/zshenv startup file. And I needed an stty command to get proper backspace/delete behavior. Because only the /etc/zshenv file seemed to be recognized, I had to put the stty command in it. The stty command works fine, but unsurprisingly produces an error in my automated jobs that ssh into the system. So I tried: if [ ${TERM} ] then stty erase ^? fi That didn't work, so I tried: if [ -n ${TERM} ] then stty erase ^? fi Someone who actually knows what they're doing will, I'm sure, instantly recognize the problem with this. I'm pretty sure TERM is indeed the variable I should be testing, but that I'm not testing it in the right way. What is the magic way? -- David Benfell, LCP [EMAIL PROTECTED] --- Resume available at http://www.parts-unknown.org/ NOTE: I sign all messages with GnuPG (0DD1D1E3). pgpkIiK4dbhQn.pgp Description: PGP signature
Re: stupid scripting question: zsh
The problem is likely the that you don't have the full path to stty in your script, and the automated jobs don't have a proper path set yet. Use the full pathname in your script and see if that works. -Derek At 04:37 PM 1/29/2007, David Benfell wrote: Hello all, I've been upgrading my FreeBSD system into a fully-fledged desktop system. zsh as installed (from the port) seems only to recognize the /etc/zshenv startup file. And I needed an stty command to get proper backspace/delete behavior. Because only the /etc/zshenv file seemed to be recognized, I had to put the stty command in it. The stty command works fine, but unsurprisingly produces an error in my automated jobs that ssh into the system. So I tried: if [ ${TERM} ] then stty erase ^? fi That didn't work, so I tried: if [ -n ${TERM} ] then stty erase ^? fi Someone who actually knows what they're doing will, I'm sure, instantly recognize the problem with this. I'm pretty sure TERM is indeed the variable I should be testing, but that I'm not testing it in the right way. What is the magic way? -- David Benfell, LCP [EMAIL PROTECTED] --- Resume available at http://www.parts-unknown.org/ NOTE: I sign all messages with GnuPG (0DD1D1E3). -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: stupid scripting question: zsh
In the last episode (Jan 29), David Benfell said: I've been upgrading my FreeBSD system into a fully-fledged desktop system. zsh as installed (from the port) seems only to recognize the /etc/zshenv startup file. And I needed an stty command to get proper backspace/delete behavior. Because only the /etc/zshenv file seemed to be recognized, I had to put the stty command in it. I'd start by figuring out why the other zsh startup scripts aren't being read. I install zsh from ports on all my systems and haven't seen this. Are you running zsh -f, or have you unset the RCS shell option from within zshenv? Either will prevent the other rc scripts from being loaded. If you run truss -f -o log zsh, do you see it try to load zshrc? Anyway, here's how to emulate zprofile, zshrc, and zlogin from within zshenv (untested). Stick this at the bottom of your zshenv: if [[ -o rcs -o login ]] ; then # code that would be better off in zprofile fi if [[ -o rcs -o interactive ]] ; then # code that would be better off in zshrc fi if [[ -o rcs -o login ]] ; then # code that would be better off in zlogin fi -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: stupid scripting question: zsh
On Mon, 29 Jan 2007 17:19:40 -0600, Dan Nelson wrote: In the last episode (Jan 29), David Benfell said: I've been upgrading my FreeBSD system into a fully-fledged desktop system. zsh as installed (from the port) seems only to recognize the /etc/zshenv startup file. And I needed an stty command to get proper backspace/delete behavior. Because only the /etc/zshenv file seemed to be recognized, I had to put the stty command in it. I'd start by figuring out why the other zsh startup scripts aren't being read. I install zsh from ports on all my systems and haven't seen this. Are you running zsh -f, or have you unset the RCS shell option from within zshenv? Either will prevent the other rc scripts from being loaded. If you run truss -f -o log zsh, do you see it try to load zshrc? Okay, I figured out how to run truss (yes, I had the PROCFS and PSEUDOFS options in my kernel). Yes, it tries to access /etc/zshrc. I was trying zlogin, which I had seen on a Linux system. So I've made *this* change, and everything now works. Thanks! Anyway, here's how to emulate zprofile, zshrc, and zlogin from within zshenv (untested). Stick this at the bottom of your zshenv: if [[ -o rcs -o login ]] ; then # code that would be better off in zprofile fi if [[ -o rcs -o interactive ]] ; then # code that would be better off in zshrc fi if [[ -o rcs -o login ]] ; then # code that would be better off in zlogin fi Thanks! -- David Benfell, LCP [EMAIL PROTECTED] --- Resume available at http://www.parts-unknown.org/ NOTE: I sign all messages with GnuPG (0DD1D1E3). pgpvMPkWipKH6.pgp Description: PGP signature
Re: stupid scripting question: zsh
In the last episode (Jan 29), David Benfell said: On Mon, 29 Jan 2007 17:19:40 -0600, Dan Nelson wrote: In the last episode (Jan 29), David Benfell said: I've been upgrading my FreeBSD system into a fully-fledged desktop system. zsh as installed (from the port) seems only to recognize the /etc/zshenv startup file. And I needed an stty command to get proper backspace/delete behavior. Because only the /etc/zshenv file seemed to be recognized, I had to put the stty command in it. I'd start by figuring out why the other zsh startup scripts aren't being read. I install zsh from ports on all my systems and haven't seen this. Are you running zsh -f, or have you unset the RCS shell option from within zshenv? Either will prevent the other rc scripts from being loaded. If you run truss -f -o log zsh, do you see it try to load zshrc? Okay, I figured out how to run truss (yes, I had the PROCFS and PSEUDOFS options in my kernel). Yes, it tries to access /etc/zshrc. I was trying zlogin, which I had seen on a Linux system. zlogin should be also read, but only on login shells. For testing purposes, you can force a login shell after you've logged in by running zsh -l. -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
OT: stupid sh scripting question
This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
In response to Robert Huff [EMAIL PROTECTED]: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi The ; after the ] ? -- Bill Moran Collaborative Fusion Inc. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
On Jan 3, 2007, at 3:07 PM, Robert Huff wrote: if [ ! -d foo] then mkdir foo fi You want a space before the ] and a semicolon after it. -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
On 1/3/07, Bill Moran [EMAIL PROTECTED] wrote: In response to Robert Huff [EMAIL PROTECTED]: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi The ; after the ] ? -- Bill Moran Collaborative Fusion Inc. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] you need a space before the ']' -- The biggest problem with communication is the illusion that it has occurred. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
In the last episode (Jan 03), Robert Huff said: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi You need a space between foo and ] . -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
On Wed, Jan 03, 2007 at 03:07:43PM -0500, Robert Huff wrote: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] It is probably not telling you ':' missing but ';' missing. It goes after the ']', plus I think the space before ']' is required. jerry Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
On 1/3/07, Jerry McAllister [EMAIL PROTECTED] wrote: On Wed, Jan 03, 2007 at 03:07:43PM -0500, Robert Huff wrote: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] It is probably not telling you ':' missing but ';' missing. It goes after the ']', plus I think the space before ']' is required. jerry Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] the ';' is not required if the 'then' statement is not on the same line as the 'if' statement. [EMAIL PROTECTED] ~% sh $ if echo foo then echo bar fi foo bar sorry for the repeat jerry (gmail's reply defaults to replying to just the sender and not everyone) -- The biggest problem with communication is the illusion that it has occurred. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT: stupid sh scripting question
Robert Huff wrote: This is probably staring me in the face: if [ ! -d foo] Missing space ^ here. ie: if [ ! -d foo ] then mkdir foo fi or perhaps more succinctly: [ -d foo ] || mkdir foo or best of all, maybe just: mkdir -p foo Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW signature.asc Description: OpenPGP digital signature
Re: OT: stupid sh scripting question
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Kevin Downey wrote: On 1/3/07, Jerry McAllister [EMAIL PROTECTED] wrote: On Wed, Jan 03, 2007 at 03:07:43PM -0500, Robert Huff wrote: This is probably staring me in the face: if [ ! -d foo] then mkdir foo fi gives me: [: missing ] It is probably not telling you ':' missing but ';' missing. It goes after the ']', plus I think the space before ']' is required. jerry Looking at rc.subr I see: if [ ! -d $linkdir ]; then warn $_me: the directory $linkdir does not exist. return 1 fi Robert Huff the ';' is not required if the 'then' statement is not on the same line as the 'if' statement. [EMAIL PROTECTED] ~% sh $ if echo foo then echo bar fi foo bar Right. As many people have said on the list already, the only issue with the original script is with the lack of a space between the last quote for foo and ]. test(1) likes having that extra space and will not work properly without it. - -Garrett -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.1 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFnCU4EnKyINQw/HARAhLZAJsG0Wk9t9RjzieA3u/EPWK3Dynv2ACcCRGZ 0e8eCk+ScQnqNrAMHrgIuZc= =rh5F -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: scripting question
(forgot to cc the list =)) Remove the word root from the crontab entry. The user should be specified only in the system crontab. On 10/3/06, jan gestre [EMAIL PROTECTED] wrote: i made a script and put on root's crontab, however it's not doing or showing the output that is forwarded to my email address correctly therefore i'm not sure if it is working or not. below is what the script look like: # # cvsrun - Weekly CVSup Run echo Subject: `hostname` weekly cvsup run /usr/local/bin/cvsup -g -L 2 /root/ports-supfile echo /usr/local/bin/portmanager -s | grep OLD echo echo cvsrun done. # i would like the output of this command /usr/local/bin/portmanager -s | grep OLD to show in my mail where i forwarded it. below is the cronjob. 30 8 * * * root /usr/local/bin/cvsrun | mail -s Daily cvsup run and portmanager user1 can someone help me to correct this script, to show the output that i want. TIA ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Best Regards, Ivan Levchenko [EMAIL PROTECTED] -- Best Regards, Ivan Levchenko [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: scripting question
On 10/3/06, Ivan Levchenko [EMAIL PROTECTED] wrote: Remove the word root from the crontab entry. The user should be specified only in the system crontab. thanks ivan, but the solution i made was i put in the /usr/local/etc/periodic/daily directory, it is now working :D On 10/3/06, jan gestre [EMAIL PROTECTED] wrote: i made a script and put on root's crontab, however it's not doing or showing the output that is forwarded to my email address correctly therefore i'm not sure if it is working or not. below is what the script look like: # # cvsrun - Weekly CVSup Run echo Subject: `hostname` weekly cvsup run /usr/local/bin/cvsup -g -L 2 /root/ports-supfile echo /usr/local/bin/portmanager -s | grep OLD echo echo cvsrun done. # i would like the output of this command /usr/local/bin/portmanager -s | grep OLD to show in my mail where i forwarded it. below is the cronjob. 30 8 * * * root /usr/local/bin/cvsrun | mail -s Daily cvsup run and portmanager user1 can someone help me to correct this script, to show the output that i want. TIA ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Best Regards, Ivan Levchenko [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
scripting question
i made a script and put on root's crontab, however it's not doing or showing the output that is forwarded to my email address correctly therefore i'm not sure if it is working or not. below is what the script look like: # # cvsrun - Weekly CVSup Run echo Subject: `hostname` weekly cvsup run /usr/local/bin/cvsup -g -L 2 /root/ports-supfile echo /usr/local/bin/portmanager -s | grep OLD echo echo cvsrun done. # i would like the output of this command /usr/local/bin/portmanager -s | grep OLD to show in my mail where i forwarded it. below is the cronjob. 30 8 * * * root /usr/local/bin/cvsrun | mail -s Daily cvsup run and portmanager user1 can someone help me to correct this script, to show the output that i want. TIA ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: scripting question
On 10/2/06, jan gestre [EMAIL PROTECTED] wrote: i made a script and put on root's crontab, however it's not doing or showing the output that is forwarded to my email address correctly therefore i'm not sure if it is working or not. below is what the script look like: ... 30 8 * * * root /usr/local/bin/cvsrun | mail -s Daily cvsup run and portmanager user1 Why don't you make this a periodic script. Put it in '/usr/local/etc/periodic/weekly/299.cvrun' and it will be run every week with the rest of your periodic; with periodic you get much better control over where output is sent. -- -- Perfection is just a word I use occasionally with mustard. --Atom Powers-- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question [newby]
On Mon, 10 Apr 2006, Malcolm Fitzgerald wrote: On 10/04/2006, at 12:39 AM, Jan Grant wrote: On Sun, 9 Apr 2006, Malcolm Fitzgerald wrote: I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ Your advice got me to step 7 where the need to pass a control structure to the loop stopped me again. I got a bash shell and I write: for dist in base dict doc games info manpages ports; do cat /mnt/6.0-RELEASE/${dist}/${dist}.?? /usr/${dist}.tgz done I put it onto three lines by typing \ at the end of each line to achieve the layout and I get the prompt . When I get to the end, ie, done I press Enter and get another prompt. How can I get the multi-line command executed? What you're doing is roughly this: (note, I supplied a separate done, you'll see why) [[[ $ for i in one two three; do \ echo $i \ done done one done two done three done $ ]]] the first done is counted as part of the echo argument list. If you terminate a line with a \ character, then the intervening newline is treated as just whitespace. Consequently, were you to use this syntax, you'd need to punctuate your script properly: for i in one two three; do \ echo $i; \ done Having said that, you don't need the \ marks, because bash (and sh) are smart enough to parse as you go and keep prompting until the command is complete. Thus you can just type: for i in one two three; do echo $i done and it'll do what you're asking. Cheers, jan -- jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/ Tel +44 (0)117 3317661 http://ioctl.org/jan/ Strive to live every day as though it was last Wednesday. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Shell scripting question [newby]
I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ At point four it offers this shell script. cut -f 1 -d '$' /usr/local/freebsd-update/work/md5all | uniq | while read X; do if [ -f $X ]; then echo $X; fi; done | sort /root/base-old Running this from root shell in konsole (bash) I get while: Expression Syntax. The various hints and clues I get from the shell, the web and man bash haven't helped me. Would someone provide the correct syntax for me? thanks malcolm ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question [newby]
On 4/9/06, Malcolm Fitzgerald [EMAIL PROTECTED] wrote: I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ At point four it offers this shell script. cut -f 1 -d '$' /usr/local/freebsd-update/work/md5all | uniq | while read X; do if [ -f $X ]; then echo $X; fi; done | sort /root/base-old Running this from root shell in konsole (bash) I get while: Expression Syntax. The various hints and clues I get from the shell, the web and man bash haven't helped me. Would someone provide the correct syntax for me? thanks malcolm ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] Are you sure it shouldnt be $X instead of X in the while clause? I dont know, never tried bash scripting before :) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question [newby]
On Sun, 9 Apr 2006, Malcolm Fitzgerald wrote: I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ At point four it offers this shell script. cut -f 1 -d '$' /usr/local/freebsd-update/work/md5all | uniq | while read X; do if [ -f $X ]; then echo $X; fi; done | sort /root/base-old Running this from root shell in konsole (bash) I get while: Expression Syntax. The various hints and clues I get from the shell, the web and man bash haven't helped me. Would someone provide the correct syntax for me? That syntax is correct for sh and bash; you're not running it, however. Double-check that after you su to root, you're really running bash. That error is what csh will tell you. -- jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/ Tel +44 (0)117 3317661 http://ioctl.org/jan/ Whenever I see a dog salivate I get an insatiable urge to ring a bell. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question [newby]
On 10/04/2006, at 12:39 AM, Jan Grant wrote: On Sun, 9 Apr 2006, Malcolm Fitzgerald wrote: I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ At point four it offers this shell script. cut -f 1 -d '$' /usr/local/freebsd-update/work/md5all | uniq | while read X; do if [ -f $X ]; then echo $X; fi; done | sort /root/base-old Running this from root shell in konsole (bash) I get while: Expression Syntax. The various hints and clues I get from the shell, the web and man bash haven't helped me. Would someone provide the correct syntax for me? That syntax is correct for sh and bash; you're not running it, however. Double-check that after you su to root, you're really running bash. That error is what csh will tell you. You are right. My user konsole is bash and I presumed that root console was too but asking $0 returned su, so I was guessing. Thanks for the help malcolm ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question [newby]
On 10/04/2006, at 12:39 AM, Jan Grant wrote: On Sun, 9 Apr 2006, Malcolm Fitzgerald wrote: I'm trying to follow the instructions at http://www.daemonology.net/freebsd-upgrade-5.4-to-6.0/ At point four it offers this shell script. cut -f 1 -d '$' /usr/local/freebsd-update/work/md5all | uniq | while read X; do if [ -f $X ]; then echo $X; fi; done | sort /root/base-old Running this from root shell in konsole (bash) I get while: Expression Syntax. The various hints and clues I get from the shell, the web and man bash haven't helped me. Would someone provide the correct syntax for me? That syntax is correct for sh and bash; you're not running it, however. Double-check that after you su to root, you're really running bash. That error is what csh will tell you. Thanks Jan, Your advice got me to step 7 where the need to pass a control structure to the loop stopped me again. I got a bash shell and I write: for dist in base dict doc games info manpages ports; do cat /mnt/6.0-RELEASE/${dist}/${dist}.?? /usr/${dist}.tgz done I put it onto three lines by typing \ at the end of each line to achieve the layout and I get the prompt . When I get to the end, ie, done I press Enter and get another prompt. How can I get the multi-line command executed? Malcolm ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Shell scripting question
I'm thinking about writing an rc.subr script that sucks in variables from a conf file. Since the rc.firewall script does just that, I thought I'd take a look at it. But I can't understand what it's doing. Here's the code: # Suck in the configuration variables. if [ -z ${source_rc_confs_defined} ]; then if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi fi Neither rc.conf nor source_rc_confs appears anywhere else in the script, so how does this suck in the variables? And what does the syntax . /etc/rc.conf do? Here's what I understand so far. If the variable source_rc_confs_defined is a zero length string, then if /etc/defaults/rc.conf is readable, then do something with it. I have no idea what the next line source_rc_confs does. Else, if /etc/rc.conf is readable, then do something with that. Can someone explain what all this does please? Paul Schmehl ([EMAIL PROTECTED]) Adjunct Information Security Officer The University of Texas at Dallas http://www.utdallas.edu/ir/security/
Re: Shell scripting question
On Mar 24, 2006, at 12:12 PM, Paul Schmehl wrote: Neither rc.conf nor source_rc_confs appears anywhere else in the script, so how does this suck in the variables? And what does the syntax . /etc/rc.conf do? Your second question is the answer to your first question: . /etc/rc.conf ...or source _file_, means to read the file into the current shell and execute those commands. It's used to load the variables set in / etc/rc.conf. Here's what I understand so far. If the variable source_rc_confs_defined is a zero length string, then if /etc/ defaults/rc.conf is readable, then do something with it. I have no idea what the next line source_rc_confs does. Else, if /etc/ rc.conf is readable, then do something with that. Yes. Take a look at the end of /etc/defaults/rc.conf and /etc/ rc.subr... -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
Yeah, but I am looking for 0 ... 8,9,11,14 are all in use ... but 0-7 are not. I want to: starting with zero, find the lowest number that is NOT in this list (where this list is the output of mdconfig -l, which shows which md devices are currently in use) Running mdconfig -l I don't get any output, however this works, it'll find the first unused number up to 25 in that list. echo '8 9 11 14' | perl -ane'@[EMAIL PROTECTED](1)[EMAIL PROTECTED];for(0..25){if(not defined $h{$_}){print qq($_\n);exit}}' If you can give me the exact output of mdconfig -l, I can modify this for you. Thank you very much - you got no output because you have no md devices in use. I have a few in use and this is the output I get: # mdconfig -l md3 md2 md1 md0 But I could just as easily get: # mdconfig -l md9 md8 md5 md3 Hmm...I just saw that that line is in perl, and I do not have perl installed on any of my 6.0 machines ... I am not sure I want to install it just for this one shell script :( Whoops, I forgot that perl isn't in the base any more. What scripting languages do you have? If you only have sh, I'll work on that, but it won't be a one-liner most likely. Or a C program. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
On Wed, 25 Jan 2006, Luke Bakken wrote: Thank you very much - you got no output because you have no md devices in use. I have a few in use and this is the output I get: # mdconfig -l md3 md2 md1 md0 But I could just as easily get: # mdconfig -l md9 md8 md5 md3 Hmm...I just saw that that line is in perl, and I do not have perl installed on any of my 6.0 machines ... I am not sure I want to install it just for this one shell script :( Whoops, I forgot that perl isn't in the base any more. What scripting languages do you have? If you only have sh, I'll work on that, but it won't be a one-liner most likely. Or a C program. I am putting this into a larger, already written /bin/sh program ... doesn't need to be one line ... Wow - thanks a lot for your help. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
Thank you very much - you got no output because you have no md devices in use. I have a few in use and this is the output I get: # mdconfig -l md3 md2 md1 md0 But I could just as easily get: # mdconfig -l md9 md8 md5 md3 Hmm...I just saw that that line is in perl, and I do not have perl installed on any of my 6.0 machines ... I am not sure I want to install it just for this one shell script :( Whoops, I forgot that perl isn't in the base any more. What scripting languages do you have? If you only have sh, I'll work on that, but it won't be a one-liner most likely. Or a C program. I am putting this into a larger, already written /bin/sh program ... doesn't need to be one line ... Wow - thanks a lot for your help. OK, this works on my cygwin install and I think it's generic enough sh programming it should work for you. You could expand the MDDEV variable to encompass all of the devices you could have, past md9. I read the mdconfig man page and it doesn't seem to have an option to list all potential devices. You'll also have to change 'echo $DEV' to whatever means you want to use to return the device from the function. It's not the most elegant solution, but it works. #!/bin/sh function find_first_mdevice { MDDEV='md0 md1 md2 md3 md4 md5 md6 md7 md8 md9' MDOUT=`mdconfig -l` for DEV in $MDDEV do if ! echo $MDOUT | grep -q $DEV then break fi done echo $DEV } find_first_mdevice ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
On Wed, 25 Jan 2006, Luke Bakken wrote: #!/bin/sh function find_first_mdevice { MDDEV='md0 md1 md2 md3 md4 md5 md6 md7 md8 md9' MDOUT=`mdconfig -l` for DEV in $MDDEV do if ! echo $MDOUT | grep -q $DEV then break fi done echo $DEV } find_first_mdevice Thank you so much - I will try it out immediatelty. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
shell scripting question (mdconfig device choosing)
Hello, When I mdconfig a device and _do not_ specify a particular numbered md device (with the -u flag), it just chooses an unused device number for me. Which makes me happy. Unfortunately, mdconfig chooses the next available device, from the highest device currently in use, regardless of whether or not there are much lower devices unused. For instance, if I have md0 and md1 in use, mdconfig will auto choose md2. Good. However if I only have md10 and md11 in use, mdconfig will NOT choose md0, it will choose md12. I need it to choose the lowest available unused device. How can I do this in a bit of /bin/sh shell code ? I can check what devices are in use with `mdconfig -l`, like so: # mdconfig -l md0 and I know how to use awk to strip away the leading md from each piece of the output ... but I do not know how to take output like: 8 9 11 14 and decide that the lowest available number is 0. How can I do this ? Thank you. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
Ensel Sharon wrote: and I know how to use awk to strip away the leading md from each piece of the output ... but I do not know how to take output like: 8 9 11 14 and decide that the lowest available number is 0. How can I do this ? % echo '9 8 11 14' | sort -nt ' ' | head -1 8 -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
On Tue, 24 Jan 2006, Chuck Swiger wrote: Ensel Sharon wrote: and I know how to use awk to strip away the leading md from each piece of the output ... but I do not know how to take output like: 8 9 11 14 and decide that the lowest available number is 0. How can I do this ? % echo '9 8 11 14' | sort -nt ' ' | head -1 8 Yeah, but I am looking for 0 ... 8,9,11,14 are all in use ... but 0-7 are not. I want to: starting with zero, find the lowest number that is NOT in this list (where this list is the output of mdconfig -l, which shows which md devices are currently in use) Thanks. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
Ensel Sharon wrote: and I know how to use awk to strip away the leading md from each piece of the output ... but I do not know how to take output like: 8 9 11 14 and decide that the lowest available number is 0. How can I do this ? % echo '9 8 11 14' | sort -nt ' ' | head -1 8 Yeah, but I am looking for 0 ... 8,9,11,14 are all in use ... but 0-7 are not. I want to: starting with zero, find the lowest number that is NOT in this list (where this list is the output of mdconfig -l, which shows which md devices are currently in use) Running mdconfig -l I don't get any output, however this works, it'll find the first unused number up to 25 in that list. echo '8 9 11 14' | perl -ane'@[EMAIL PROTECTED](1)[EMAIL PROTECTED];for(0..25){if(not defined $h{$_}){print qq($_\n);exit}}' If you can give me the exact output of mdconfig -l, I can modify this for you. Luke ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: shell scripting question (mdconfig device choosing)
Luke, On Tue, 24 Jan 2006, Luke Bakken wrote: Yeah, but I am looking for 0 ... 8,9,11,14 are all in use ... but 0-7 are not. I want to: starting with zero, find the lowest number that is NOT in this list (where this list is the output of mdconfig -l, which shows which md devices are currently in use) Running mdconfig -l I don't get any output, however this works, it'll find the first unused number up to 25 in that list. echo '8 9 11 14' | perl -ane'@[EMAIL PROTECTED](1)[EMAIL PROTECTED];for(0..25){if(not defined $h{$_}){print qq($_\n);exit}}' If you can give me the exact output of mdconfig -l, I can modify this for you. Thank you very much - you got no output because you have no md devices in use. I have a few in use and this is the output I get: # mdconfig -l md3 md2 md1 md0 But I could just as easily get: # mdconfig -l md9 md8 md5 md3 Hmm...I just saw that that line is in perl, and I do not have perl installed on any of my 6.0 machines ... I am not sure I want to install it just for this one shell script :( ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Shell scripting question
I've written a script to check apache to make sure it's running *and* logging. One of the variables I create is named DATEHOUR, and it's created by parsing the output of date in such a way that all I get is the hour (using awk and cut.) I'm comparing DATEHOUR to LOGHOUR, which represents the the most recent hour that the log was written to I've run in to a small problem I'm not sure how to solve. When the hour is less than 10, the script generates an arithmetic expression error. Here's part of the script so you can visualize what I'm trying to do: PROG=/usr/local/sbin/apachectl LOG=/var/log/httpd-access.log PID=`/bin/ps -auxw | grep http | grep root | grep -v grep | awk '{print $2}'` DATE=`date | awk '{print $4}' | cut -d':' -f1,2` LOGDATE=`ls -lsa ${LOG} | awk '{print $9}'` DATEHOUR=`echo ${DATE} | cut -d':' -f1` LOGHOUR=`echo ${LOGDATE} | cut -d':' -f1` DATEMIN=`echo ${DATE} | cut -d':' -f2` LOGMIN=`echo ${LOGDATE} | cut -d':' -f2` LOGGING=1 if [ $((DATEMIN)) -gt $((LOGMIN+15)) ]; then LOGGING=0 elif [ $((DATEHOUR)) -ne $((LOGHOUR)) ] [ $((DATEMIN+60)) -gt $((LOGMIN+15)) ]; then LOGGING=0 fi When DATEHOUR is less than 10 (01-09), the script generate an arithmetic expression, variable substition error. I'm pretty certain it's because of the leading zero, so I'm trying to figure out how to strip that out. I thought that parameter expansion would do it, but I get some odd (to me) results. Assume DATE is 09. echo ${DATE:0,0} 09 echo ${DATE:0,1} 9 echo ${DATE:1,1} 9 I would have thought that 0,0 would return only the first character and 1,1 would return only the second, but that is obviously not the case. How can I strip the leading character from the string so that I can test to see if it's zero? Paul Schmehl ([EMAIL PROTECTED]) Adjunct Information Security Officer University of Texas at Dallas AVIEN Founding Member http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question
To get the date in the right format you could simply use date +%H Greetz, Ice Paul Schmehl schrieb: I've written a script to check apache to make sure it's running *and* logging. One of the variables I create is named DATEHOUR, and it's created by parsing the output of date in such a way that all I get is the hour (using awk and cut.) I'm comparing DATEHOUR to LOGHOUR, which represents the the most recent hour that the log was written to I've run in to a small problem I'm not sure how to solve. When the hour is less than 10, the script generates an arithmetic expression error. Here's part of the script so you can visualize what I'm trying to do: PROG=/usr/local/sbin/apachectl LOG=/var/log/httpd-access.log PID=`/bin/ps -auxw | grep http | grep root | grep -v grep | awk '{print $2}'` DATE=`date | awk '{print $4}' | cut -d':' -f1,2` LOGDATE=`ls -lsa ${LOG} | awk '{print $9}'` DATEHOUR=`echo ${DATE} | cut -d':' -f1` LOGHOUR=`echo ${LOGDATE} | cut -d':' -f1` DATEMIN=`echo ${DATE} | cut -d':' -f2` LOGMIN=`echo ${LOGDATE} | cut -d':' -f2` LOGGING=1 if [ $((DATEMIN)) -gt $((LOGMIN+15)) ]; then LOGGING=0 elif [ $((DATEHOUR)) -ne $((LOGHOUR)) ] [ $((DATEMIN+60)) -gt $((LOGMIN+15)) ]; then LOGGING=0 fi When DATEHOUR is less than 10 (01-09), the script generate an arithmetic expression, variable substition error. I'm pretty certain it's because of the leading zero, so I'm trying to figure out how to strip that out. I thought that parameter expansion would do it, but I get some odd (to me) results. Assume DATE is 09. echo ${DATE:0,0} 09 echo ${DATE:0,1} 9 echo ${DATE:1,1} 9 I would have thought that 0,0 would return only the first character and 1,1 would return only the second, but that is obviously not the case. How can I strip the leading character from the string so that I can test to see if it's zero? Paul Schmehl ([EMAIL PROTECTED]) Adjunct Information Security Officer University of Texas at Dallas AVIEN Founding Member http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Frank Mueller eMail: [EMAIL PROTECTED] Mobil: +49.177.6858655 Fax: +49.951.3039342 emendis GmbH Hofmannstr. 89, 91052 Erlangen, Germany Fon: +49.9131.817361 Fax: +49.9131.817386 Geschaeftsfuehrer: Gunter Kroeber, Volker Wiesinger Sitz Erlangen, Amtsgericht Fuerth HRB 10116 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question
--On Monday, September 12, 2005 20:37:22 +0200 Frank Mueller - emendis GmbH [EMAIL PROTECTED] wrote: To get the date in the right format you could simply use date +%H That solves one-half of the problem. I would still have to get the hour from the file into the correct format. Otherwise I'll simply move the error message to a different variable. Paul Schmehl ([EMAIL PROTECTED]) Adjunct Information Security Officer University of Texas at Dallas AVIEN Founding Member http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question
On 9/12/05, Paul Schmehl [EMAIL PROTECTED] wrote: How can I strip the leading character from the string so that I can test to see if it's zero? This'll strip the 0, while leaving other numbers intact: $ X=09 $ echo ${X#0} 9 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Shell scripting question
--On Monday, September 12, 2005 13:17:05 -0700 David Kirchner [EMAIL PROTECTED] wrote: On 9/12/05, Paul Schmehl [EMAIL PROTECTED] wrote: How can I strip the leading character from the string so that I can test to see if it's zero? This'll strip the 0, while leaving other numbers intact: $ X=09 $ echo ${X#0} 9 Thanks, David. That's exactly what I needed, and now that you've pointed it out to me, I see (reading the specs) how that is it. I just didn't understand what I was reading before you pointed it out. Paul Schmehl ([EMAIL PROTECTED]) Adjunct Information Security Officer University of Texas at Dallas AVIEN Founding Member http://www.utdallas.edu/ir/security/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
scripting question, killing a process safely
I am recording audio tapes to wav files using gramofile. I'd like to be able to walk away and automatically shut down the process without corrupting the wav file. I know the tape duration so I was planning to use the following script. I'd appreciate a better or more refined approach: (sleep 2700; killall gramofile) -- Joe Sotham If the only prayer you say in your entire life is Thank You, that will suffice. - Meister Eckhart To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message