Re: Shell scripting woes.

2004-02-26 Thread Jan Grant
On Wed, 25 Feb 2004, Mathias Haas wrote:

> Oh my! What stupidity! Of course. I'm afraid sometimes my DOS-roots are
> revealed...  Thanks!

In general, you ought to be aware that cron sets up only a minimal
environment. If you want your scripts to run predictably then you
probably ought to ensure the first thing they do is to recreate the
environment you're after: setting $PATH, the working directory, umask,
and so on.

-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
Boycott Arabic numerals! What have they ever done for us?
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes

2004-02-25 Thread mathias
> On Tue, 24 Feb 2004 17:56:49 +0100 (CET)
> [EMAIL PROTECTED] wrote:
>
>> Hello guys! I have two questions about shellscripts:
>
> Your second question seems to have been addressed, so here's something
> for your first question...
>
>> 1) I have a backup job that 'tar's a lot of files and currently I
>> redirect all output of the job to a log. Tar unfortunately lists all
>> directories that it goes through, even if nothing is 'tar'ed in those
>> directories. So my logfile contains all my directories. I want to
>> filter out all lines in my tar-log that ends with slash ("/") since
>> those are directories. I want to sort of do an inverse grep on the
>> last character when tarring. Like: tar -cvf myback.tar |grep -v "all
>> lines that end with slash" > log.txt. All files that are backed up
>> contain the whole directory path (that's how I want it) - so I can't
>> simply do a reverse grep for the slash-char. Maybe you could do
>> something with awk? I'm a total rookie with awk, so I'm lost there...
>
> Try
>
>   tar -cvf myback.tar | grep -v '/$'
>
> The $ in the grep pattern indicates "end of line".
>
> -Chris

Yes! That's exactly what I wanted! Thanks a lot!

Cheers,
Mathias

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes

2004-02-24 Thread Chris Pressey
On Tue, 24 Feb 2004 17:56:49 +0100 (CET)
[EMAIL PROTECTED] wrote:

> Hello guys! I have two questions about shellscripts:

Your second question seems to have been addressed, so here's something
for your first question...

> 1) I have a backup job that 'tar's a lot of files and currently I
> redirect all output of the job to a log. Tar unfortunately lists all
> directories that it goes through, even if nothing is 'tar'ed in those
> directories. So my logfile contains all my directories. I want to
> filter out all lines in my tar-log that ends with slash ("/") since
> those are directories. I want to sort of do an inverse grep on the
> last character when tarring. Like: tar -cvf myback.tar |grep -v "all
> lines that end with slash" > log.txt. All files that are backed up
> contain the whole directory path (that's how I want it) - so I can't
> simply do a reverse grep for the slash-char. Maybe you could do
> something with awk? I'm a total rookie with awk, so I'm lost there...

Try

tar -cvf myback.tar | grep -v '/$'

The $ in the grep pattern indicates "end of line".

-Chris
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Mathias Haas
Julien Gabel wrote:

The following works fine, here is the detail:

$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:50:11 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:50 /tmp/test.bash*
$
$ cat /tmp/test.bash
#!/usr/local/bin/bash
echo start > /tmp/test.txt
$
$ crontab -l
* * * * * /tmp/test.bash
$
$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:51:17 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:46 /tmp/test.bash*
-rw-r--r--  1 jgabel  wheel   6 Feb 24 22:51 /tmp/test.txt
$
$ cat /tmp/test.txt
start
$
Can you try *stricly* the same thing?
 

 

Sure (this is run as root):
$ cd /tmp
$ date ; ls -lF /tmp/test.*
Tue Feb 24 23:25:56 CET 2004
-rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
$
$ cat test.bash
#!/usr/local/bin/bash
echo start > test.txt
$ crontab -l
* * * * * /usr/local/sbin/pure-ftpwho -w > /www/data/ftpstatus.html
* * * * * /tmp/test.bash
$ date ; ls -lF /tmp/test.*
Tue Feb 24 23:26:08 CET 2004
-rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
$
Not much of difference I'm afraid.
   

There is a little difference : you are running it as 'root', and
no explicit path is given for "test.txt" in "test.bash". Can you
give us the result of :
 # ls -lF ~root/test.txt

 

Oh my! What stupidity! Of course. I'm afraid sometimes my DOS-roots are 
revealed...  Thanks!

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Julien Gabel
>> The following works fine, here is the detail:
>>
>> $ date ; ls -lF /tmp/test.*
>> Tue Feb 24 22:50:11 CET 2004
>> -rwxr-x---  1 jgabel  wheel  49 Feb 24 22:50 /tmp/test.bash*
>> $
>> $ cat /tmp/test.bash
>> #!/usr/local/bin/bash
>> echo start > /tmp/test.txt
>> $
>> $ crontab -l
>> * * * * * /tmp/test.bash
>> $
>> $ date ; ls -lF /tmp/test.*
>> Tue Feb 24 22:51:17 CET 2004
>> -rwxr-x---  1 jgabel  wheel  49 Feb 24 22:46 /tmp/test.bash*
>> -rw-r--r--  1 jgabel  wheel   6 Feb 24 22:51 /tmp/test.txt
>> $
>> $ cat /tmp/test.txt
>> start
>> $
>>
>> Can you try *stricly* the same thing?

> Sure (this is run as root):
> $ cd /tmp
> $ date ; ls -lF /tmp/test.*
> Tue Feb 24 23:25:56 CET 2004
> -rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
> $
> $ cat test.bash
> #!/usr/local/bin/bash
> echo start > test.txt
>
> $ crontab -l
> * * * * * /usr/local/sbin/pure-ftpwho -w > /www/data/ftpstatus.html
> * * * * * /tmp/test.bash
> $ date ; ls -lF /tmp/test.*
> Tue Feb 24 23:26:08 CET 2004
> -rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
> $
>
> Not much of difference I'm afraid.

There is a little difference : you are running it as 'root', and
no explicit path is given for "test.txt" in "test.bash". Can you
give us the result of :

  # ls -lF ~root/test.txt

-- 
-jg.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Mathias Haas
Julien Gabel wrote:

As a reply to both answers, here's a script that wont' run:
#!/usr/local/bin/bash
echo start > test.txt
...and here is bash:
[EMAIL PROTECTED] /usr/local/etc]>> whereis bash
bash: /usr/local/bin/bash
this is /var/log/cron
Feb 24 19:20:00 p3-550 /usr/sbin/cron[27988]: (root) CMD
(/usr/local/etc/test.sh)
This is the crontab entry:
* * * * * /usr/local/etc/test.sh
(At the moment, I have no shell parameters or other parameters in
crontab, another crontab-job runs fine, but that's an executable
file.)
 



The following works fine, here is the detail:

$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:50:11 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:50 /tmp/test.bash*
$
$ cat /tmp/test.bash
#!/usr/local/bin/bash
echo start > /tmp/test.txt
$
$ crontab -l
* * * * * /tmp/test.bash
$
$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:51:17 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:46 /tmp/test.bash*
-rw-r--r--  1 jgabel  wheel   6 Feb 24 22:51 /tmp/test.txt
$
$ cat /tmp/test.txt
start
$
Can you try *stricly* the same thing?

 

Sure (this is run as root):
$ cd /tmp
$ date ; ls -lF /tmp/test.*
Tue Feb 24 23:25:56 CET 2004
-rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
$
$ cat test.bash
#!/usr/local/bin/bash
echo start > test.txt
$ crontab -l
* * * * * /usr/local/sbin/pure-ftpwho -w > /www/data/ftpstatus.html
* * * * * /tmp/test.bash
$ date ; ls -lF /tmp/test.*
Tue Feb 24 23:26:08 CET 2004
-rwxr-x---  1 root  wheel  45 Feb 24 23:24 /tmp/test.bash*
$
Not much of difference I'm afraid.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Julien Gabel
>> As a reply to both answers, here's a script that wont' run:
>> #!/usr/local/bin/bash
>> echo start > test.txt
>>
>> ...and here is bash:
>> [EMAIL PROTECTED] /usr/local/etc]>> whereis bash
>> bash: /usr/local/bin/bash
>>
>> this is /var/log/cron
>> Feb 24 19:20:00 p3-550 /usr/sbin/cron[27988]: (root) CMD
>> (/usr/local/etc/test.sh)
>>
>> This is the crontab entry:
>> * * * * * /usr/local/etc/test.sh
>> (At the moment, I have no shell parameters or other parameters in
>> crontab, another crontab-job runs fine, but that's an executable
>> file.)


The following works fine, here is the detail:

$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:50:11 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:50 /tmp/test.bash*
$
$ cat /tmp/test.bash
#!/usr/local/bin/bash
echo start > /tmp/test.txt
$
$ crontab -l
* * * * * /tmp/test.bash
$
$ date ; ls -lF /tmp/test.*
Tue Feb 24 22:51:17 CET 2004
-rwxr-x---  1 jgabel  wheel  49 Feb 24 22:46 /tmp/test.bash*
-rw-r--r--  1 jgabel  wheel   6 Feb 24 22:51 /tmp/test.txt
$
$ cat /tmp/test.txt
start
$

Can you try *stricly* the same thing?

-- 
-jg.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Jason Taylor
Mathias Haas wrote:
Julien Gabel wrote:

Hello guys! I have two questions about shellscripts:
2) The same backup job - is written as a bash script, and it works
perfectly when run by hand, but it won't run as a cron job.

Are you using a full path in the shebang at the top of the script?
Such as:
#!/bin/sh
or
#!/usr/local/bin/bash
  


And more generally, is the ${PATH} variable set correctly according
to all the tools/utility used along your script?
 

As a reply to both answers, here's a script that wont' run:
#!/usr/local/bin/bash
echo start > test.txt
...and here is bash:
[EMAIL PROTECTED] /usr/local/etc]>> whereis bash
bash: /usr/local/bin/bash
this is /var/log/cron
Feb 24 19:20:00 p3-550 /usr/sbin/cron[27988]: (root) CMD 
(/usr/local/etc/test.sh)

This is the crontab entry:
* * * * * /usr/local/etc/test.sh
(At the moment, I have no shell parameters or other parameters in 
crontab, another crontab-job runs fine, but that's an executable file.)

/mathias

Have you checked write permissions on whatever directory test.txt is 
trying to be created in?
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Andrew Hall
You might wanna check the users mailbox.  Cron send mail on errors. 

Drew

On Tue, 2004-02-24 at 16:11, Mathias Haas wrote:
> It is executable and it didn't have a newline at the end, it does now - 
> but there's still no difference...
> Do you have to do something to get FreeBSDs (4.6.2)  cron to run 
> shellscripts?
> ..and I can still run the script "by hand"
> 
> Lowell Gilbert wrote:
> 
> >Mathias Haas <[EMAIL PROTECTED]> writes:
> >
> >  
> >
> >>As a reply to both answers, here's a script that wont' run:
> >>#!/usr/local/bin/bash
> >>echo start > test.txt
> >>
> >>
> >
> >Is it executable?
> >Does the last line have a newline at the end?
> >___
> >[EMAIL PROTECTED] mailing list
> >http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> >To unsubscribe, send any mail to "[EMAIL PROTECTED]"
> >  
> >
> ___
> [EMAIL PROTECTED] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Mathias Haas
It is executable and it didn't have a newline at the end, it does now - 
but there's still no difference...
Do you have to do something to get FreeBSDs (4.6.2)  cron to run 
shellscripts?
..and I can still run the script "by hand"

Lowell Gilbert wrote:

Mathias Haas <[EMAIL PROTECTED]> writes:

 

As a reply to both answers, here's a script that wont' run:
#!/usr/local/bin/bash
echo start > test.txt
   

Is it executable?
Does the last line have a newline at the end?
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"
 

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Lowell Gilbert
Mathias Haas <[EMAIL PROTECTED]> writes:

> As a reply to both answers, here's a script that wont' run:
> #!/usr/local/bin/bash
> echo start > test.txt

Is it executable?
Does the last line have a newline at the end?
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Julien Gabel
 Hello guys! I have two questions about shellscripts:
 2) The same backup job - is written as a bash script, and it
 works perfectly when run by hand, but it won't run as a cron job.

>>> Are you using a full path in the shebang at the top of the script?
>>> Such as:
>>>
>>> #!/bin/sh
>>> or
>>> #!/usr/local/bin/bash

>>And more generally, is the ${PATH} variable set correctly according
>>to all the tools/utility used along your script?

> As a reply to both answers, here's a script that wont' run:
> #!/usr/local/bin/bash
> echo start > test.txt
>
> ...and here is bash:
> [EMAIL PROTECTED] /usr/local/etc]>> whereis bash
> bash: /usr/local/bin/bash
>
> this is /var/log/cron
> Feb 24 19:20:00 p3-550 /usr/sbin/cron[27988]: (root) CMD
> (/usr/local/etc/test.sh)
>
> This is the crontab entry:
> * * * * * /usr/local/etc/test.sh
> (At the moment, I have no shell parameters or other parameters in
> crontab, another crontab-job runs fine, but that's an executable
> file.)

Here it runs fine... but /usr/local/etc/test.sh is and must be
executable.

-- 
-jg.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Mathias Haas
Julien Gabel wrote:

Hello guys! I have two questions about shellscripts:
2) The same backup job - is written as a bash script, and it works
perfectly when run by hand, but it won't run as a cron job.
 

Are you using a full path in the shebang at the top of the script?
Such as:
#!/bin/sh
or
#!/usr/local/bin/bash
   

And more generally, is the ${PATH} variable set correctly according
to all the tools/utility used along your script?
 

As a reply to both answers, here's a script that wont' run:
#!/usr/local/bin/bash
echo start > test.txt
...and here is bash:
[EMAIL PROTECTED] /usr/local/etc]>> whereis bash
bash: /usr/local/bin/bash
this is /var/log/cron
Feb 24 19:20:00 p3-550 /usr/sbin/cron[27988]: (root) CMD 
(/usr/local/etc/test.sh)

This is the crontab entry:
* * * * * /usr/local/etc/test.sh
(At the moment, I have no shell parameters or other parameters in 
crontab, another crontab-job runs fine, but that's an executable file.)

/mathias



___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes.

2004-02-24 Thread Julien Gabel
>> Hello guys! I have two questions about shellscripts:
>> 2) The same backup job - is written as a bash script, and it works
>> perfectly when run by hand, but it won't run as a cron job.

> Are you using a full path in the shebang at the top of the script?
> Such as:
>
> #!/bin/sh
> or
> #!/usr/local/bin/bash

And more generally, is the ${PATH} variable set correctly according
to all the tools/utility used along your script?

-- 
-jg.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Shell scripting woes

2004-02-24 Thread Peter Risdon
[EMAIL PROTECTED] wrote:

Hello guys! I have two questions about shellscripts:

2) The same backup job - is written as a bash script, and it works
perfectly when run by hand, but it won't run as a cron job. 

Are you using a full path in the shebang at the top of the script? Such as:

#!/bin/sh

or

#!/usr/local/bin/bash

or whatever.

PWR.

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"