Sponsored Content
Full Discussion: LAST command with Year
Homework and Emergencies Emergency UNIX and Linux Support LAST command with Year Post 302430165 by kkeng808 on Thursday 17th of June 2010 01:30:57 AM
Old 06-17-2010
MySQL

THx Guys,

In the mean time I have written one script which will give me the users last login in the system ( All users )
Code:
# !/usr/bin/bash

ssh unadm@$1 ' lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g' > /userlogins

cat userlogins | grep : > temp | awk -F":" '{print $2}' temp | xargs -I {} perl -le "print scalar localtime ({})" > temp1
awk -F":" '{print $1}' temp > temp2
paste temp2 temp1
rm temp temp1 temp2

In the above I want to execute the first line command highlighted below as root using sudo..

ssh unadm@$1 ' lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g' > /userlogins


Can anyone explain how can i use sudo in this remote command

---------- Post updated 06-17-10 at 12:30 AM ---------- Previous update was 06-16-10 at 07:50 PM ----------

Its done Well guys Smilie

Code:
# !/usr/bin/bash
if [ $# -eq 1 ]
then
echo "IPADDRESS : $1"
ssh unadm@$1 ' echo "HOSTNAME: $(hostname) \t  DATE: $(date)"'
ssh unadm@$1 "sudo lsuser -a time_last_login ALL | sed 's/\ time_last_login=/:/g'" > userlogins
cat userlogins | grep : > temp; awk -F":" '{print $2}' temp | xargs -I {} perl -le "print scalar localtime ({})" > temp1
awk -F":" '{print $1}' temp > temp2
paste temp2 temp1 | awk -F" " '{ printf "%-20s %s %s %-2d %s %d\n", $1, $2, $3, $4, $5, $6 }'
rm temp temp1 temp2
exit
else
echo "USAGE: $0 <IPADDRESS>"
exit 1
fi
bash-3.00$

Output as belowSmilie

Code:
HOSTNAME: test1     DATE: Thu Jun 17 00:11:13 CDT 2010
root                 Thu Jul 24 05:02:01 2008
testuser             Sun Jan 25 12:49:22 2009
mqm                  Tue Sep 9  04:23:46 2008
db2inst1             Sat Sep 12 00:38:38 2009
jrnj0i0              Mon Apr 13 05:51:25 2009
prp0i0               Mon Sep 7  00:24:04 2009

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find out the exact year in "Last modified time" using ls command

Hi, I understand that the ls command with "-l" option generates the "last modified time" of specific directory. However, some generated results displayed the "last modified time" with detail about the last modified year, for example: -rwxrwxrwx+ 1 smith dev 10876 May 16 2005 part2 ... (6 Replies)
Discussion started by: Dophlinne
6 Replies

2. UNIX for Dummies Questions & Answers

listing year in ls command

Hi all .. As per rule i searched the forum i am not able found out ... I want to display the year in when listing the files .. when i use ls -lt it is not displaying files with recent 6 month old .. I know that perderabo has written a script for that if you give that link it will be... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

3. Shell Programming and Scripting

Printing Year in ls -ltr command

Hi, When retrieving parameters of a file using ls command i need to print the year part . When i do ls -ltr the following output is displayed -rwxrwxrwx 1 d_infd d_infd 1711 Jan 8 2004 wf1.class. Here the year part is not displayed only Jan 8 is displayed. Can any one... (9 Replies)
Discussion started by: ragugct
9 Replies

4. Shell Programming and Scripting

Last Command not giving year

Hi All, i want the last login details along with year. i tried below command but not giving me the year of last login. last <$Userid> | head -1 i heard that if it is current year then it wont display the year else it will display the year. is it so? if yes then , is there any way of... (1 Reply)
Discussion started by: ani_rvce
1 Replies

5. UNIX for Dummies Questions & Answers

Last Command not giving year

Hi All, i want the last login details along with year. i tried below command but not giving me the year of last login. last <$Userid> | head -1 i heard that if it is current year then it wont display the year else it will display the year. is it so? if yes then , is there any way of... (1 Reply)
Discussion started by: ani_rvce
1 Replies

6. Linux

uptime command output when the server is running more than one year?

What is the uptime command output when the server is running more than one year? My doubt is whether it show in number of days format or number years and number of days format? For example, Assume the server is running 400 days 3 hrs 3 min 3 secs. The output like 400 days 3:3 min or 1 year 5... (3 Replies)
Discussion started by: maruthu
3 Replies

7. UNIX for Dummies Questions & Answers

Unix man command to find out month of the year?

how can i display month of the year i was born with using man command? thanks (2 Replies)
Discussion started by: janetroop95
2 Replies

8. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

9. UNIX for Dummies Questions & Answers

Command to print previous year in UNIX

hi all, I use date +%Y which gives Current year. Requirement: I want previous year to be printed. Please help me. Note: I tried date +%d/%m/%Y -d "-1 years" which is not working. (10 Replies)
Discussion started by: wasim999
10 Replies

10. UNIX for Beginners Questions & Answers

Insert year in ls -l command

Hi All, Have a file where i stored ls -l command output, -rw-r--r-- 1 360 600 94255 Jan 01 11:16 file1_2020.csv -rw-r--r-- 1 360 600 114573 Dec 29 11:10 file2_2019.csv -rw-r--r-- 1 360 600 41006 Dec 30 11:09 file3_2019.csv -rw-r--r-- 1 360 ... (9 Replies)
Discussion started by: kumarinfa
9 Replies
IO::AtomicFile(3)					User Contributed Perl Documentation					 IO::AtomicFile(3)

NAME
IO::AtomicFile - write a file which is updated atomically SYNOPSIS
use IO::AtomicFile; ### Write a temp file, and have it install itself when closed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->close || die "couldn't install atomic file: $!"; ### Write a temp file, but delete it before it gets installed: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->delete; ### Write a temp file, but neither install it nor delete it: my $FH = IO::AtomicFile->open("bar.dat", "w"); print $FH "Hello! "; $FH->detach; DESCRIPTION
This module is intended for people who need to update files reliably in the face of unexpected program termination. For example, you generally don't want to be halfway in the middle of writing /etc/passwd and have your program terminate! Even the act of writing a single scalar to a filehandle is not atomic. But this module gives you true atomic updates, via rename(). When you open a file /foo/bar.dat via this module, you are actually opening a temporary file /foo/bar.dat..TMP, and writing your output there. The act of closing this file (either explicitly via close(), or implicitly via the destruction of the object) will cause rename() to be called... therefore, from the point of view of the outside world, the file's contents are updated in a single time quantum. To ensure that problems do not go undetected, the "close" method done by the destructor will raise a fatal exception if the rename() fails. The explicit close() just returns undef. You can also decide at any point to trash the file you've been building. AUTHOR
Primary Maintainer David F. Skoll (dfs@roaringpenguin.com). Original Author Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com). REVISION
$Revision: 1.2 $ perl v5.16.2 2005-02-10 IO::AtomicFile(3)
All times are GMT -4. The time now is 12:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy