date command not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date command not working
# 1  
Old 04-11-2011
date command not working

hi
Code:
 

#!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
# 2  
Old 04-11-2011
Hi.

I think it unlikely that date would be in /sbin. More likely in /bin.

You also miss a / in your "shebang":

Code:
# cat perl1
#!/usr/bin/perl -w
local ($date) = `/bin/date "+%D %X" ` ;
print $date

# ./perl1
11/04/11 01:15:28 PM

# 3  
Old 04-12-2011
hi
i added / still same error is coming.
in sbin folder date command is working.
but above script is not working
# 4  
Old 04-12-2011
You mean that typing:
Code:
/usr/sbin/date

from the command line works?

(/usr/bin is in the PATH, so just typing date from any directory will work)
# 5  
Old 04-12-2011
yes. thats correct. but one of my perl files is having the code.
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
# 6  
Old 04-12-2011
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:
Code:
ls -l /sbin/date
ls -l /usr/sbin/date

# 7  
Old 04-25-2011
i execute it from root

ls -l /sbin/date not found


ls -l /usr/sbin/date not found
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

3. Shell Programming and Scripting

Script to get last working date

Problem : we need a command that will give previous day date and previous day should be mon-fri only. Example :if we are running a command on Monday , it will give Friday ‘s date not Sunday’s . Few more restrictions : Command should be working in NM n/w. Hard coding of date should be avoided.... (11 Replies)
Discussion started by: Downsouth
11 Replies

4. UNIX for Dummies Questions & Answers

Date Validation not working

Hi Experts, I have a date validation script in that i will validate the date for a given format and search in the logs for that date. The script logic is very simple like below. Validate_Date() { is_valid=1 while do date_format=$(date "+$1") echo -e "Please enter the $2 date like... (6 Replies)
Discussion started by: senthil.ak
6 Replies

5. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

6. Shell Programming and Scripting

Date command is not working properly

Hi, in my script, i take the last month by a=$(date --date '1 month ago' +%Y%m) i expect that it give me in this month "March" as result 201402, but linux gave me 201403. IMPe@ABC123:> ~/date --date '1 month ago' +%Y%m 201403 i'm reasonably confused. Any idea? Thanks in advance, ... (2 Replies)
Discussion started by: IMPe
2 Replies

7. Shell Programming and Scripting

Working with bash and date

Hello all, I'm trying to substract 1 minute from the current date and take the hour and minute (for filename purpose). 1) If I want hour an minute from current time I can use: timetmp=$(date +"%H:%M") 2) To substract 1 minute from current time I can use: timetmp=$(date --date "$dte -1... (8 Replies)
Discussion started by: Lord Spectre
8 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Dummies Questions & Answers

Date command to obtain the last month is not working correctly..

Hello, I could not find the exactly same post here.. so I will explain what I did to get the last month using date command. I used date +%Y-%m -d "-1 months" to get the last month. However, the returned value of above command on 2009/10/31 was 2009 10 and not 2009 09.. and the... (9 Replies)
Discussion started by: tigersk
9 Replies

10. Shell Programming and Scripting

working with date

I wan to convert any field having date in the file from the follwoing format 5/1/2003 to 2003-05-01. This file is tab delimited. Please help. (2 Replies)
Discussion started by: dsravan
2 Replies
Login or Register to Ask a Question