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
# 8  
Old 06-18-2009
I hope with "find" command with "mtime" option you can do it easily.

Please check for the same once.
# 9  
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


yes i did, this code works
Code:
print " " $0 >> /u/bin/Test

Code:
psg telnetd | awk -v hn=`hostname` 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)
                {
                 
                 user=$1
                 printf("Killing telnetd\n")
                 system("date >> //u/bin/Test")
                 print " " $0 >> /u/bin/Test
 system("/u/bin/remsh hn -l user; /u/bin/kill -9 pid >> /u/bin/Test ");
                               
                }
          }'


Last edited by Anteus; 06-19-2009 at 04:43 AM.. Reason: modification incode
# 10  
Old 06-18-2009
Quote:
Originally Posted by panyam
I hope with "find" command with "mtime" option you can do it easily.

Please check for the same once.

process of finding the process is done. now required to kill and put process details in the u/bin/Test...
# 11  
Old 06-19-2009
Anteus,

I am extremely sorry, I misread your post .

What i mean here is ,

please put all your commands together with arguments in a file and try to execute that file.In you code your passing arguments to the system command . which i think is not possible.

better try like this :
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
                 print "Killing telnetd \n" >> /u/bin/Test

                 system("date >> /u/bin/Test")

                print " /u/bin/remsh " hostn " -l " user ";/u/bin/kill -9 " pid  >> "op.sh"

                              
                }

          }        END { if [ -f "op.sh" ] { chmod +x "op.sh" ; system("./op.sh >> /u/bin/Test ") } } '

Let me know , for any further information in this.
# 12  
Old 06-19-2009
Quote:
Originally Posted by panyam
Anteus,

I am extremely sorry, I misread your post .

What i mean here is ,

please put all your commands together with arguments in a file and try to execute that file.In you code your passing arguments to the system command . which i think is not possible.

better try like this :
Code:
psg telnetd |  awk -v hn= `hostname` 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)
                {
                 user=$1
                 print "Killing telnetd \n" >> /u/bin/Test
 
                 system("date >> /u/bin/Test")
 
                print " /u/bin/remsh " hn " -l " user ";/u/bin/kill -9 " pid  >> "op.sh"
 
 
                }
 
          }        END { if [ -f "op.sh" ] { chmod +x "op.sh" ; system("./op.sh >> /u/bin/Test ") } } '

Let me know , for any further information in this.
Hi.

I am not allowed to use a file as such only a log file is maintained. in which process killing time has to be entered .. cant we do within awk.?

and in order to kill process within awk can we use system command like this system("u/bin/kill -9 pid") ?

Last edited by Anteus; 06-19-2009 at 04:43 AM.. Reason: modification in the code (-v) option added
# 13  
Old 06-19-2009
You can use , but you cannot pass the "pid" directly as you mentioned.

better you do something like this :

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
                 print "Killing telnetd \n" >> /u/bin/Test
                 system("date >> /u/bin/Test")
                 op="/u/bin/remsh " hostn " -l " user "; /u/bin/kill -9 " pid ">> /u/bin/Test";
                 system(op ) 
                 } 
                 } '

# 14  
Old 06-19-2009
Quote:
Originally Posted by panyam
You can use , but you cannot pass the "pid" directly as you mentioned.

better you do something like this :

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
                 print "Killing telnetd \n" >> /u/bin/Test
                 system("date >> /u/bin/Test")
                 op="/u/bin/remsh " hostn " -l " user "; /u/bin/kill -9 " pid ">> /u/bin/Test";
                 system(op ) 
                 } 
                 } '

hi panyam

thanks a lot. Its working fine now.

Regards
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