Visit Our UNIX and Linux User Community


Date format of remote system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date format of remote system
# 1  
Old 08-24-2009
Date format of remote system

Hi,

I am trying to write a small code where i capture the output of ls command on a remote system.
However i want a certain consistency in the date format being received
Say i want it to be dd/mm/yyyy format.

how can i do this?

This is what i am doing currently
Code:
FTP1=`ssh ${USER_FTP_origin}@${MACHINE_FTP_origin} 2> /dev/null << ! 
    cd ${PATH_ORIGIN}
    ls -1 $File_name
    exit
!`


This however sometimes gives me the date in dd/mm/yyyy and sometimes in mm/dd/yyyy format.
Please suggest what can be done

Thanks

Last edited by Franklin52; 08-24-2009 at 09:37 AM.. Reason: Please use code tags!
# 2  
Old 08-24-2009
Which date? ls -1 just gives the names, one per row. Whichever date you mean, it could be because the remote machines are different?
Smilie

Else there is always the possibility to use date format options.
Code:
man date

# 3  
Old 08-24-2009
Hi,

I understood my mistake.Thanks for the reply anyways.
I will try to be a little more careful in posting my queries next time.

Cheers
# 4  
Old 08-24-2009
On GNU-Linux (coreutils 6.10).

For ls command:
Code:
 ls  -l --time-style=+'%d/%m/%Y'

If it is a time stamp that you need, insert this in your script:
Code:
date +'%d/%m/%Y'

# 5  
Old 08-24-2009
You can (partially) influence the output format of ls by setting the LANG environment variable to a certain locale, eg:
Code:
$ touch -t 200801010000.00 test.file
$ LANG=C ls -l test.file
-rw-r--r-- 1 pludi users 0 Jan  1  2008 test.file
$ LANG=en_GB ls -l test.file
-rw-r--r-- 1 pludi users 0 2008-01-01 00:00 test.file
$ LANG=en_US ls -l test.file
-rw-r--r-- 1 pludi users 0 2008-01-01 00:00 test.file
$ LANG=de_AT ls -l test.file
-rw-r--r-- 1 pludi users 0  1. Jän 2008  test.file

# 6  
Old 08-24-2009
Please can you post one example of each of the different "ls" formats you have seen, stating which Operating System was involved in each and every case. Please create the examples on the same day when dd != mm.

Translating timestamps from "ls -la" to numeric date format has been covered extensively on this site. If there is a small variety of formats to deal with why not create a flag file on each computer which you can read in your script.

If you are the administrator of these machines you could use "C" programming language to get stat (man 2 stat) information in a consistent format across a wide variety of platfoms.

Previous Thread | Next Thread
Test Your Knowledge in Computers #300
Difficulty: Easy
The basis for the first versions of the Slackware Linux distributions was Debian Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

4. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

5. Shell Programming and Scripting

get system date, format it, pass it as a parameter to a perl script - all in cron job

I am trying to get the string containing date - in a specfic format actually, although I think that part is inconsequencial - 1110226^1110226^1110226^1110226^1110226 - through echo or printf or in some other way - created within a cront job and passed as a parameter to a perl script. Now, I know... (3 Replies)
Discussion started by: v8625
3 Replies

6. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. UNIX for Advanced & Expert Users

Change of System Date format

I have this T5220 server with Solaris 10 installed on to it. Now when I fire the command "date" the o/p I get is as follows : bash-3.00# date Tuesday, February 9, 2010 7:25:24 PM IST whereas I want the date to appear in this format: bash-3.00# date Tue Feb 9 19:26:06 IST 2010 ... (3 Replies)
Discussion started by: ksahay@123
3 Replies

8. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies

Featured Tech Videos