hi
#!usr/bin/perl -w
local ($date) = `/sbin/date "+%D %X" ` ;
print $date
when i run this in ksh shell it is giving the below error
sh: /sbin/date: not found
but same code is working and displaying date and time in sh shell.
what could be the reason.
pls help
Scott
2
Hi.
I think it unlikely that date would be in /sbin. More likely in /bin.
You also miss a / in your "shebang":
# cat perl1
#!/usr/bin/perl -w
local ($date) = `/bin/date "+%D %X" ` ;
print $date
# ./perl1
11/04/11 01:15:28 PM
hi
i added / still same error is coming.
in sbin folder date command is working.
but above script is not working
Scott
4
You mean that typing:
/usr/sbin/date
from the command line works?
(/usr/bin is in the PATH, so just typing date from any directory will work)
yes. thats correct. but one of my perl files is having the code.
#!/usr/bin/perl -w
local ($date) = `/sbin/date "+%D %X" ` ;
print $date
while execute this code gives error
sh: /sbin/date: not found
i need to run from same path.how to make it
If /usr/sbin/date is working, then consider changing your perl script to use /usr/sbin/perl.
Sounds like you are on a fairly old platform where /sbin and /usr/sbin/ contain statically linked executables.
What is the output of:
ls -l /sbin/date
ls -l /usr/sbin/date
i execute it from root
ls -l /sbin/date not found
ls -l /usr/sbin/date not found
you must check enviroment variables.
what 's the output these?
which date
which ls
Not sure what really wrong with your code... Try this... which is your OS?
#!/usr/bin/perl -w
local ($date) = `/usr/bin/date "+%D %X" ` ;
print $date
regards,
Ahamed
Maybe ls command is problem
check your ls command
if you use centos/fedora/redhat ..
# rpm -V `rpm -qa|grep ^coreutils`
However you must be sure env variables
you can try like this and lets see results..
#!/usr/bin/perl
($sec,$min,$hour,$mday,$mon,$year,$wday,
$yday,$isdst)=localtime(time);
printf "%4d-%02d-%02d %02d:%02d:%02d\n",
$year+1900,$mon+1,$mday,$hour,$min,$sec;
or try
#!/usr/bin/perl
#local ($date) = `/bin/date "+%D %X" ` ;
#print $date
$ENV{'PATH'} = '/bin:/usr/bin:/sbin;/usr/sbin';
local ($date) = `date "+%D %X" ` ;
print $date
regards
ygemici