Re: Re: bash Shell Scripting Question

2012-09-20 Thread Jan Henrik Sylvester
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}

Re: bash Shell Scripting Question

2012-09-20 Thread Martin McCormick
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

Re: bash Shell Scripting Question

2012-09-20 Thread Polytropon
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

bash Shell Scripting Question

2012-09-19 Thread Martin McCormick
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

Re: bash Shell Scripting Question

2012-09-19 Thread Mihai Donțu
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

Re: bash Shell Scripting Question

2012-09-19 Thread Polytropon
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

Re: simple (and stupid) shell scripting question

2010-02-16 Thread Christian Weisgerber
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

Re: simple (and stupid) shell scripting question

2010-02-15 Thread Eray Aslan
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

Re: simple (and stupid) shell scripting question

2010-02-15 Thread Christian Weisgerber
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

Re: simple (and stupid) shell scripting question

2010-02-15 Thread Nerius Landys
#!/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

simple (and stupid) shell scripting question

2010-02-14 Thread Nerius Landys
#!/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

Re: simple (and stupid) shell scripting question

2010-02-14 Thread Eray Aslan
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

Re: simple (and stupid) shell scripting question

2010-02-14 Thread Nerius Landys
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

Re: Shell scripting question - incrementing

2008-02-19 Thread Dominic Fandrey
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,

Shell scripting question - incrementing

2008-02-19 Thread Paul Schmehl
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

Re: Shell scripting question - incrementing

2008-02-19 Thread Derek Ragona
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:

Re: Shell scripting question - incrementing

2008-02-19 Thread Pietro Cerutti
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

Re: Shell scripting question - incrementing

2008-02-19 Thread Paul Schmehl
--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

Re: mysqldump/gzip shell scripting question...

2007-08-17 Thread Alex Zbyslaw
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

mysqldump/gzip shell scripting question...

2007-08-16 Thread Eric Crist
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/

Re: mysqldump/gzip shell scripting question...

2007-08-16 Thread Garrett Cooper
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

Re: Shell scripting question [newby]

2006-04-10 Thread Jan Grant
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

Shell scripting question [newby]

2006-04-09 Thread Malcolm Fitzgerald
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

Re: Shell scripting question [newby]

2006-04-09 Thread Daniel A.
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

Re: Shell scripting question [newby]

2006-04-09 Thread Jan Grant
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

Re: Shell scripting question [newby]

2006-04-09 Thread Malcolm Fitzgerald
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

Re: Shell scripting question [newby]

2006-04-09 Thread Malcolm Fitzgerald
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

Shell scripting question

2006-03-24 Thread Paul Schmehl
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

Re: Shell scripting question

2006-03-24 Thread Charles Swiger
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

Re: shell scripting question (mdconfig device choosing)

2006-01-25 Thread Luke Bakken
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

Re: shell scripting question (mdconfig device choosing)

2006-01-25 Thread Ensel Sharon
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

Re: shell scripting question (mdconfig device choosing)

2006-01-25 Thread Luke Bakken
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

Re: shell scripting question (mdconfig device choosing)

2006-01-25 Thread Ensel Sharon
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

shell scripting question (mdconfig device choosing)

2006-01-24 Thread Ensel Sharon
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

Re: shell scripting question (mdconfig device choosing)

2006-01-24 Thread Chuck Swiger
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

Re: shell scripting question (mdconfig device choosing)

2006-01-24 Thread Ensel Sharon
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 ? %

Re: shell scripting question (mdconfig device choosing)

2006-01-24 Thread Luke Bakken
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

Re: shell scripting question (mdconfig device choosing)

2006-01-24 Thread Ensel Sharon
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

Shell scripting question

2005-09-12 Thread Paul Schmehl
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

Re: Shell scripting question

2005-09-12 Thread Frank Mueller - emendis GmbH
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

Re: Shell scripting question

2005-09-12 Thread Paul Schmehl
--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

Re: Shell scripting question

2005-09-12 Thread David Kirchner
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 ___

Re: Shell scripting question

2005-09-12 Thread Paul Schmehl
--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: $