prints the date to STDOUT and returns the exit status of /bin/date, in this case '0'. So the following if condition fails. You have already printed out the date simply by calling system('/bin/date').
In the second example `/bin/date' returns the string that you get by running the command but doesnt print anything to STDOUT. Since any non null string (except for the string that contains just '0') evaluates to true in perl your if clause prints 'Cant get date'.
At a rough guess its the second way you want to use but like this:
Hi, I'm trying to do something like this: range= `expr `date '+%m'` - 1` and it does not work. How can I tell it to evaluate an expression within another expression evaluation? I was at first worried that `date '+%m'` would return a string but apparently expr does the math okay normally, so the... (3 Replies)
I'm always concerned I might be abusing backticks within my scripts. A current script I'm writing has this for example:
stripscriptname=`echo $scriptname | sed 's/\(.*\)\..*/\1/'`
stripsearch=`echo $searchpattern | tr -d ' ,/'`
Both of these variables are set inside the script (in fact,... (2 Replies)
hi,
i have a perl script that runs as a cron job... Once in a while, the perl
script fails with:
Can't locate <module>.pm in @INC (@INC contains: .............)
because one of the perl modules specified in the "use" statements is
unavailable due to an NFS glitch.
Is there some... (1 Reply)
I have having problems with an IF statement in my perl script:
if ($model eq "N\\A") {}
elsif ($kernel =~ m/xen/) {
$model = ("Virtual Machine\n")};
What i am trying to accomplish is if the model is set to "N\A" and the kernel variable has xen somewhere in it i would like to change... (3 Replies)
So far, all I have been able to come up with is:
if ($check=~/no/ || $check=~/n/)
but the problem with this, is that it looks for any character and the if statement is true. So if I wanted to check for an argument "-help" or lets say a variable string that could be a file name. Then... (2 Replies)
Hi everyone. This is a bit of a perl/linux mixed question. I am trying to redirect STDOUT of chsh by using the following line of perl code.
system ("chsh -s /sbin/nologin $testing 1>/dev/null");
This should redirect STDOUT to /dev/null but it won't do that for some odd reason. Any ideas or... (6 Replies)
Hi all,
Here is my code:
my $x = `bash -c \" ls -l filename | awk '{print \$5}'\"`;
print "$x\n";
This will run the first part of the bash script but not the awk command. It therefore gives output of:
-rw-r--r-- 1 root root 13619200 2012-04-25 08:16 filename
I am actually trying to... (0 Replies)
I have been testing a new script and cannot figure out why my `cat spath` will not execute on the remote machine?
sudo ssh -p 22344 -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.1.6 "find `cat spath` -depth"
cat: spath: No such file or directory
but... (0 Replies)
I'm trying to make a dialog window that prints the output of grep that takes the output of find. Unfortunately my nested backticks don't work.
Here is the dialog window:
dialog --stdout --title "test" --backtitle "test" --msgbox "Test:\n `grep -l "${tablica}" `find $string``" 16 60I think I... (2 Replies)
I have a file like
file.
file.TODAY.THISYEAR
file.TODAY.LASTYEARI want to substitute the words in caps with their actual values so that output should look like
file.140805
file.140805.2014
file.140805.2013For this I am reading the file line bye line in an array and using multiple map... (1 Reply)