![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | |
| Registered User Join Date: May 2007 Location: Berkeley, CA
Posts: 140
| Calling lockf from the shell line works fine, but in the script, it fails Code: % lockf -t 30 /usr/party/log/party.log sleep 30 Code: #!/usr/bin/perl
use warnings;
my $value;
while (True)
{
if(`w | grep cd | grep party`) {
`lockf -t 30 /usr/party/log/party.log sleep 30`;
sleep(30);
}
else {
print "not logged in\n";
}
sleep(1);
}
Quote:
| |
| Overworked_PhD is offline | |
| | #2 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,207
| It seems silly to me to use a perl script just to issue shell commands; why don't you put them in a shell script? To lock a file in perl use flock(). |
| MK27 is online now | |
| | #3 |
| Registered User Join Date: May 2007 Location: Berkeley, CA
Posts: 140
| |
| Overworked_PhD is offline | |
| | #4 | |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,207
| Quote:
Code: #!/bin/bash lockf -t 30 /usr/party/log/party.log sleep 30 I do not have a "lockf" command on my system, so I can't help you with the syntax*, but shell scripts are executed by the shell one line at a time. If it works on the command line, it will work in a shell script. Here: Code: !/bin/bash
if grep "bash" | grep "cdalten" > /dev/null
then lockf -t 30 /usr/party/log/party.log sleep 30
else echo "not logged in"
fi
*eg, I'm assuming "sleep 30" at the end is a parameter and not a typo for "&& sleep 30" Last edited by MK27; 04-12-2009 at 01:41 PM. | |
| MK27 is online now | |
| | #5 |
| Registered User Join Date: May 2007 Location: Berkeley, CA
Posts: 140
| Your script only works after I press ctrl-c. I'm assuming the process is doing some kind of forking that I'm not aware of. |
| Overworked_PhD is offline | |
| | #6 | |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,207
| Quote:
Code: cat textfile | thatscript.sh or thatscript.sh < textfile | |
| MK27 is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| This works fine with IP 127.0.0.1 but fails with my REAL IP. | azjherben | Networking/Device Communication | 15 | 05-19-2009 10:28 PM |
| shell script basic question | PedroTuga | Linux Programming | 1 | 09-09-2006 03:24 AM |
| It works just fine but | jcmhex | C++ Programming | 3 | 04-24-2005 06:53 PM |
| Contest Results - May 27, 2002 | ygfperson | A Brief History of Cprogramming.com | 18 | 06-18-2002 01:27 PM |
| Greenhand want help! | leereg | C Programming | 6 | 01-29-2002 06:04 AM |