Create Date

Someone told me there is no such thing as a (file) "created_on" date in Linux...


Similar Content



Redirection. Help Pls.

Hello there. Im stuck on a task.

it`s the task:
Search the file 'data' for all of the lines that contain the pattern 'linux'
and put those lines in the file 'matches'.

You entered: grep "linux" date > matches
Please try again.

I tried lots of variants
1) grep linux date > matches
2) grep 'linux' date > matches
3) grep linux date >> matches

May be something`s wrong with grep command?
I just dont get it >.>; it should work fine. Where is my mistake folks?

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.

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!

How: Date Of The Command Ran?

Hi Forum members,

I'm interested to get the date on which particular command was ran.

I've below in my .bashrc

Code:
export HISTTIMEFORMAT="%d/%m/%y %T "

I ran history | grep "cp" | less

I get an output like:

Quote:
1288 27/05/15 09:12:55 sacct -j 767151 --format=elapsed,ncpus,state
27/05 is today's date. But I'm interested for the date, the above output was ran.

What am I missing?

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.

Syntax Error: Unexpected End Of File

Hi!
I wrote a script shell about changing IP of the httpd.conf from text file and saving a new httpd.conf file for all IPs in the text file. The code is below, Im using mremote on windows (RHEL Release 5.7), and getting this error:
./script1.sh: line 19: syntax error: unexpected end of file

Please help me about that error. Thanks!

(ps: line 19 is the last line in the code => done < "$filename" )

#!/bin/bash

DATE='date +%Y%m%d_%H:%M:%S'
NAME=httpd_ip_change
EXTENSION=conf
max=10

filename="$1"
while read -r line

for ((i=2; i<=$max; ++i ))

do
touch $NAME$i.$EXTENSION.$DATE

sed "s/<VirtualHost 10.11.92.81:80>/$line/g" ./httpd.conf > $NAME$i.$EXTENSION.$DATE

done < "$filename"

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";
}

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.

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 ??

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