File Time Stamp And Time As Printed By Date Showing Difference

Hi
Please see below actions.

$ touch abcd #abcd does not exist before
$ ls -l abcd
-rw-r--r-- 1 james games 0 Apr 17 15:01 abcd
$ date
Fri Apr 17 15:39:55 IST 2015

Why is there about 38 minutes difference even though I type commands in quick succession ?

Thank you.


Similar Content



Linux Pro's And Noobs! A Challenge, Please Take A Crack At This! (TIME SENSATIVE,)

Do it like this is your situation, your server, and the dir that are mentioned below, act like they are yours! im just looking for an accurate answer!
(student of O'Rielly School of Tech)


whenever you log in, your shell executes commands that it finds in your dotfiles, specifically .bash_login. In your .bash_login, add a series of commands that will first create a directory named ~/sysadmin1/my_peeps/$DATE, where $DATE is today's date in the format mmddyy. This command should succeed whether or not the directory ~/sysadmin1/my_peeps already exists. Then, it will redirect the output of the w command (which lists the currently logged in users on the system) to a file inside this newly created directory called users.$TIME, where $TIME is the current time in the format hhmmss (use 24 hour time).

In order to do this, you must use a new concept: assignment of a variable from the output of a command. For example, in order to set the variable EXAMPLEDATE using the unformatted output of the date command, you would do the following:

EXAMPLEDATE=`date`

The characters surrounding the date command are called "backticks." They are usually located on the same key as ~. They are not single quotation marks. This is actually another kind of expansion called "Command Substitution" (you can learn more in bash's manpage).

For this project, you can use the date command to get both the date and the current time, however, you will have to consult date's manpage to find out how to change the formatting.

Bash Echo Date+string In The Same Line

I would like to print the date followed by a string (an indication of what's going on at that time) to a file. With this intention I've tried

Code:
date >> date.txt && echo "something start" >> date.txt

That gives me

Code:
Sun May 17 01:08:28 BRT 2015
something start

How to get both at the same line? Like this

Code:
Sun May 17 01:08:28 BRT 2015 something start

Trying To Install Korora 21 But Haning.

I've been testing out a couple of LiveDVD systems and I like Korora 21. I'm now trying to install this distro but the Anaconda Installer does not seem to be working.

Each time I get to the screen with the keyboard, date/time and installation destinations. The Data/time and INstallation destinations options have a white box around them. The Date/Time shows a message "Restoring Hardware time" or something like that and the Installation Destination is showing a message "Probing Storage".

I've let it sit for about 10 minutes and nothing changes. I've tried clicking on the Date/Time option and the Installation Destination option with no luck. When you hover over the Installation Destination option it shows "No Disks Selected".

Can someone help me with this please? I really like the LiveDVD and would like to give it a go.

Script To Find The File Creation Time Is More Than Ten Minutes

Hi All,

Im trying to create a script which checks the creation time of a file and if it is more than ten minutes, send out an alert.

For ex : Creation date of file is 10:30 AM
current time is 10:45 AM

Then send an alert/ message.

This is the script i wrote below :

Code:
#!/bin/ksh

filename="/apps/log/file.txt"

if [ -f "${filename}" ]
then
        createTime=`ls -lad "${filename}" | awk '{print $8}'`
        echo "$createTime"
        currentTime=`date '+%M'`
        echo "$currentTime"
        DIFF=$(( $currentTime - $createTime )) 
        echo "$DIFF"

else

        exit 1

fi

I am getting syntax error on the subraction when i try to run this script . I can understand that creation time and current time is in different format thats y this error throws, but i dont know how to rectify it .

I need to find out if the file creation time is more than ten minutes.

Please help me in achieving this output.

Simple Script Needed To Calculate How Many "15" Minutes Are In A Time Stamp

Hello,

I am performing some work on some mp3 files. One the functions requires me to know how many "15 minutes" are in a particular file.

For instance, I need some code that will produce the following values from the given time stamp:

01:52:34.40 = 7
00:47:15.32 = 3
00:02:56.41 = 0
00:36:01.09 = 2

Any ideas?

Another Question, Linux Pros, And Noobs, Take A Crack.

to create a directory named sysadmin1/my_peeps/$DATE ,, am i to: echo sysadmin1/my_peeps/$DATE >> .bash_login ?? or do i: vi .bash_login and manually type the commands in there??,, i have the DATE variable already set. im looking for another way besides using mkdir.. thats my first question..

my real problem and second question is, how do i redirect the output of the w command to a file in my_peeps.. so, after that dir is created, do i do w > sysadmin1/my_peeps ??

TimeZone Problem

Dear Friends ,

My date value shows One hour ahead from the present time in BDT . I stay on Asia/Dhaka zone and +6.00 . Please look @ the below output :

------------------------------------------------------------
[root@pbldc-ntpsrv Asia]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Dhaka"
UTC=true
ARC=false
-------------------------------------------------------------


But , My problem is , the below Date command output shows 'BDST' instead of 'BDT' .
------------------------------------
"[root@pbldc-ntpsrv Asia]# date
Sat May 9 16:59:37 BDST 2015
-------------------------------------
But it should be :

---------------------------------
[root@pbldc-ntpsrv Asia]# date
Sat May 9 15:59:37 BDT 2015
---------------------------------

---------------------
[root@pbldc-ntpsrv ~]# date +Z
BDST --Should be BDT
[root@pbldc-ntpsrv ~]# date +%z
+0700 --Should bt +0600
[root@pbldc-ntpsrv ~]#

------------------------------------


How I fix it in redhat lnux 5.5 server .

Script Queries

Hi,

Below is the output of the "date" command:
Thu Apr 2 16:07:59 SGT 2015

After assigning the output to a parameter as follows:
DATE=`date`

The output has changed when "echo $DATE":
Thu Apr 2 16:09:40 SGT 2015
^^

The "2" has moved forward.

I don't want the "2" to move forward, please advise how to go about it.

Thanks in advance.

Age Calculator, Pass By Reference Problem.

Hi, fellow programmers.
I am programming about an age calculator.
It's simple:
1, get the input date 'today', check if its valid
2, get the input date 'birthday', check if it's valid and before 'today'
3, calculate the difference and output.
This is a assignment due tomorrow and I have written the most of it, just needs some debugging, mostly about pass by reference. I declared date1&date2 at main and I have no idea how to call the value of them if I want to calculate them at another function. I guess I should probably declare them at struct Date, but I am not sure.
I would really appreciate it if you guys could tell me what to do.
Code:
/************************************************************
 *
 * Project 4: How Old Are You Really?
 *
 * Author: xx
 * Date: 6 May 2015
 *
 * This is a program designed to calculates the difference 
 * between two dates, which will be expressed in terms of
 * years, months and days.
 *
 ***********************************************************/

#include <bjarne/std_lib_facilities.h>

struct Date {
    int month;
    int day;
    int year;
// Member functions
Date get_date();
Date get_birth_date();
bool is_valid_date(int year, int month, int day);
bool is_before(Date& date1, Date& date2);
Date calculate_age(Date& date1,Date& date2);
};

// Declaration
Date get_date();
Date get_birth_date();
bool is_valid_date(int year, int month, int day);
bool is_before(Date& date1, Date& date2);
Date calculate_age(Date& date1,Date& date2);

int main()
{
    Date date1 = get_date();
    Date date2 = get_birth_date();
    Date get_date();
    // Check if the date is correct
    if (! is_valid_date(year, month, day))
    error("Date is not valid.");
    // Run how old or not?
    char go_on;
    cout << "Would you like to see how old you are (y/n)?\n";
    cin >> go_on;
    if (go_on=='n'){
    cout << "You are so chicken!";
    return 0;}
    else if (go_on!='y')
    error("Please enter y for yes or n for no.");
    Date get_birth_date();
    // Is birthday valid as well?
    if (! is_valid_date(int year, int month, int day))
    error("Date is not valid.");
    // Is the birthday before 'today'?
    if (!(is_before(Date& date1, Date& date2)))
    error("Your birthday should not be later than today, terminator.");
    // Calculate and give the answer.
    Date calculate_age();
}

Date get_date()
{
    Date date1;
    cout << "Welcome to the age calculator!\n";
    cout << "Please enter today's date (mm/dd/yyyy): ";
    int m;
    int d;
    int y;
    // To ignore the '/' during reading
    char slash;
    cin >> m;
    date1.month = m;
    cin >> slash;
    cin >> d;
    date1.day = d;
    cin >> slash;
    cin >> y;
    date1.year = y;
    cout << "Date entered was "<< date1.month << "/" << date1.day << "/" << date1.year <<"\n";
}

Date get_birth_date()
{
    Date date2;
    cout << "Please enter your birth date (mm/dd/yyyy): "; 
    int m;
    int d;
    int y;
    // To ignore the '/' during reading
    char slash;
    cin >> m;
    date2.month = m;
    cin >> slash;
    cin >> d;
    date2.day = d;
    cin >> slash;
    cin >> y;
    date2.year = y;
    cout << "Your birthday is "<< date2.month << "/" << date2.day << "/" << date2.year <<"\n";
}

// Is date valid?
bool is_vaild_date(int year, int month, int day)
{
    if (day<0)
    return false;
    if (month<1 || month>12)
    return false;
    // Check if the date exists or not considering there are have
    // different days when month varies
    int days_in_month=31;
    switch (month){
    case 2:
    days_in_month=28;
    break;
    case 4: case 6: case 9: case 11:
    days_in_month=30;
    break;
    }
    if (days_in_month<day)
    return false;
    return true;
}

//Date check - is birthday before 'today'?
bool is_before(Date& date1, Date& date2)
{
    if (Date& date1.year<Date& date2.year)
    return false;
    else if (Date& date1.month<Date& date2.month)
    return false;
    else if (Date& date1.day< Date& date2.day)
    return false;
    return true;
}

// Calculation
Date calculate_age(Date& date1,Date& date2)
{
    Date date3;
    date3.day = date1.day - date2.day;
    date3.month = date1.month - date2.month;
    date3.year = date1.year - date2.month;
    if (date3.day<0){
        date3.day = 30 + date3.day;
        date3.month = date3.month - 1;
    }
    if (date3.month<0){
        date3.month = 12 + date3.day;
        date3.year = date3.year - 1;
    }
    cout <<"You are " << date3.year <<" years, "<< date3.month <<" months, and " << date3.day <<" days old.\n";
}

Process Substitution With Awk, Output Splitting Incorrectly

I have the following code to extract two dates using awk, which are then read into two awk variables new and old respectively.
Each dates on the html file pulled with curl request is in this format:
2015-04-06 09:40:37
And two are being extracted
However the strings are being split on white space within the date strings. I tried changing OFS to ',', but it was still splitting incorrectly.
Code:
read dateStrNew dateStrOld < <(curl -k -q "$curl_call" | html2text | gawk '/Newest Sequence/ { new=$3" "$4 }/Oldest Sequence/ \
 {old=$3" "$4}END {OFS=","; print new,old }')  //new = date, old = date

Both parts of the date are being assigned to each variable using $3 and $4, then the space needs to be added back in so that the string can be used afterwards with a date command.

I just can't work out what is wrong, any help would be very much appreciated! Thanks!