how to make a log.txt and add date and time when use ls,touch and find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make a log.txt and add date and time when use ls,touch and find
# 1  
Old 06-18-2009
how to make a log.txt and add date and time when use ls,touch and find

Hey guy,

how to make the log.txt file and record date and time when ls, touch and find command run?

Thanks
Boly
# 2  
Old 06-18-2009
I think you want this...
Code:
alias ls="/bin/ls $@;date >> <PATH_OF_THE_LOG>/log.txt"

similarly do for other commands
# 3  
Old 06-18-2009
Quote:
Originally Posted by rakeshawasthi
I think you want this...
Code:
alias ls="/bin/ls $@;date >> <PATH_OF_THE_LOG>/log.txt"

similarly do for other commands
can you tell me why this code is throwing error

psg telnetd | awk '{
system("print("%s",$0)>> /u/bin/Test") }'


it shows an error like this
it shows error
awk: Cannot divide by zero when using the modulo operator.
The input line number is 1.
The source line number is 18.
# 4  
Old 06-18-2009
Mr . Anteus,

Please don't multipost your question in different posts.

Code:
 print("%s",$0)

wont work .

try something like this :

Code:
awk '{print "print " $0 >> "op" ;system("chmod +x op");\
 system("./op >> /u/bin/Test"); system("rm op") }'

# 5  
Old 06-18-2009
Quote:
Originally Posted by panyam
Mr . Anteus,

Please don't multipost your question in different posts.

Code:
 print("%s",$0)

wont work .

try something like this :

Code:
awk '{print "print " $0 >> "op" ;system("chmod +x op");\
 system("./op >> /u/bin/Test"); system("rm op") }'

Hi panyam..
henceforth i wont.

can you please explain me what this means
Code:
print "print " $0

. and why do we need op ..why cant we print directly into the Test.

regards.

code is working all fine..thanks

Last edited by Anteus; 06-18-2009 at 09:31 AM..
# 6  
Old 06-18-2009
did u try in this way ?..

Code:
psg telnetd  | awk '{print "print " $0 >> "op" ;system("chmod +x op");\ system("./op >> /u/bin/Test"); system("rm op") }'

For your requirement i think , there is no need to use system command. Just to show u the usage of that i have given you the solution.

below code do your job

Code:
psg telnetd  | awk '{ print $0 }'  >> /u/bin/Test

# 7  
Old 06-18-2009
Quote:
Originally Posted by panyam
did u try in this way ?..

Code:
psg telnetd  | awk '{print "print " $0 >> "op" ;system("chmod +x op");\ system("./op >> /u/bin/Test"); system("rm op") }'

For your requirement i think , there is no need to use system command. Just to show u the usage of that i have given you the solution.

below code do your job

Code:
psg telnetd  | awk '{ print $0 }'  >> /u/bin/Test

hii..
i m trying to kill all those process who have are running from more than 50 mins..i think i will require system command
here is the code
Code:
 
psg telnetd | awk current=`date +%M`'{
                pid=$2
                uid=$1
                split($5,a,":")
                command=($5 ~ /^[A-Z]/)? $9:$8
                time=a[2]
                diff=time-current
                if(diff > 50)
                {
                 hostn=./hostname
                 user=$1
                 printf("Killing telnetd\n")
                 system("date >> //u/bin/Test")
                 print " " $0 >> "//u/bin/Test"
                 system("/u/bin/remsh hostn -l user; /u/bin/kill -9 pid >> /u/bin/Test ");
                               
                }
          }'


Last edited by Anteus; 06-19-2009 at 02:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In HP-UX how to find the date time difference ?

Hello, In HP-UX how to find the date time difference ? Start time: 28-APR-2019 21:36:01 End time : 29-APR-2019 00:36:04 ---------------------- Difference is ---------------------- Much appreciate any pointer or view on this. ... (3 Replies)
Discussion started by: Siva SQL
3 Replies

2. Red Hat

Touch - changing date and time

Hi, I am facing a problem with the command - TOUCH on Linux. See the example below: File on Linux: rw-rw-r-- user1 user1 Jan 01 09:00 test.txt The file - test.txt was created by the user - user1. Now, I want to change the date and time, but using other user - user2 The user2... (12 Replies)
Discussion started by: brjohnsmith
12 Replies

3. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

4. Shell Programming and Scripting

How to find last updated date and time of a folder in Perl?

Hi All, I have a process which after some time continues move a files to some folder(say the name of the folder is logdir) What i am trying to do is as the files are coming to the logdir folder, I want the latest updated time and date of the folder in PERL. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

5. Shell Programming and Scripting

ksh shell script to add date (YYYYMMDDHHMISS) to all .txt files in a folder

Everyday 15 files are written to a folder \app\where\thefiles\are\destined\CURRFOLDER Task1: I need to add date in YYYYMMDDHHMISS format to each of them. Example: File: ACCOUNT.txt Should be updated as: ACCOUNT_20101005175059.txt Task 2: After I update the files, they need to be ... (2 Replies)
Discussion started by: Duminix
2 Replies

6. Shell Programming and Scripting

how to make a log file of extract time

Dear All, Please apology to me if this question already posted, because I try to find it but not found. I have make bash script to automatically download data from ftp and this running very well. and after the data downloaded it will automatically extract the data and keep in the specific... (2 Replies)
Discussion started by: chenboly
2 Replies

7. Shell Programming and Scripting

Find the file names from date/time: Need help

Hi All, I really need help in figuring out how to determine the filenames from the time that is specified as parameter. The script should take as input - the start time and end time in minutes and also start date and end date. Example: reporter.sh -instance Instance_Name -startTime 13:10... (0 Replies)
Discussion started by: chiru_h
0 Replies

8. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

9. UNIX for Advanced & Expert Users

find formatted filename with date time

Hi, I operate and use HF radars along the California coast for ocean surface currents. The devices use Mac OS as the control and logging software. The software generates thousands of files a week and while I've used PERL in the past to solve the problems of finding files I come to realize some... (6 Replies)
Discussion started by: dpath2o
6 Replies

10. AIX

find files with specific date and time

Hi, I wanna to find files with specific date and time. I know this command: ls -ltr /system1/*.505 | grep 'Jan 18 09:00'. I want the 'Jan 18 09:00' not hard coded, I want it coming from the system date and time. And I want the time varies from 09:00-09:05. Is this possible without heavy... (3 Replies)
Discussion started by: itik
3 Replies
Login or Register to Ask a Question