Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Subtracting Variables which are commands Post 1771 by PxT on Thursday 29th of March 2001 10:55:10 AM
Old 03-29-2001
This gets tricky because what if their login time is 2:59, and the logout time is 3:10. 3:10-2:59=? The shell doesn't know that you are trying to subtract times, it just sees numbers with a colon in the middle. A better way to do this might be to use the 'last' command, as one of the fields it provides is the total log in time.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Subing Variables with commands.

Hi, I'm back! Ok, I'm trying to use a variable with a value of a unix command. So when I try a=`ls`, then echo $a I get the correct answer. But when I try it with a pipe: a=`ls | wc -c`, then echo $a I get: filename: a: command not found I've tried so many ways I presumme it's the pipe... (1 Reply)
Discussion started by: Astudent
1 Replies

2. Shell Programming and Scripting

Referencing variables in commands

The script I am writing must be able to run several commands (tar, gzip etc) on filenames that are supplied by variables. I am unsure as to what syntax is required/ideal when referencing variables in filenames. The following is a sample command that I would like the script to execute: tar cvf... (3 Replies)
Discussion started by: mharley
3 Replies

3. Shell Programming and Scripting

Using variables in sed commands

Hi there, I need to be able to put the hostid of my box into a file (replacing the text "enter_hostid_here" so i tried sed -e 's/enter_hostid_here/`hostid`/g' inputfile > outputfile but it takes the `hostid` literally as text .....how can I get this info into the file (ideally in a single... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

4. Shell Programming and Scripting

Storing commands in $variables.

Hi I'm trying to store commands in variables... like so.. # lastcmd=" $t1 | $t2 | $t3 | $t4 | sort | uniq" t1="sed -e 's/http:/<li><a href=\"http:/'" t2="sed -e 's/http:.*/&\">&<\/a>Web Link<br>/'" t3="sed -e 's/.*. mailto:/<li><a href=\"mailto:/'" t4="sed -e... (7 Replies)
Discussion started by: Paulw0t
7 Replies

5. Shell Programming and Scripting

subtracting variables in ksh

hi all, how do i subract variables in shell ?? am trying to space out the headers and the output generated by the shell so they all line up : currently the output is like this : servers : users server1 : 10 latestServer : 50 so i thought... (3 Replies)
Discussion started by: cesarNZ
3 Replies

6. Shell Programming and Scripting

Using variables within awk/sed commands

Can I use my own variables within awk and sed for example: I've written a while loop with a counter $i and I want to use the value of $i within sed and awk to edit certain lines of text within a data file. I want to use : sed '1s/$/texthere/g' data.csv Like this: sed '$is/$/$age/g' data.csv... (5 Replies)
Discussion started by: mustaine85
5 Replies

7. Shell Programming and Scripting

Piping through commands read as variables from file

This is going to be part of a longer script with more features, but I have boiled it down to the one thing that is presently stumping me. The goal is a script which checks for updates to web pages that can be run as a cron job. The script reads (from a tab-delim file) a URL, an MD5 digest, and an... (1 Reply)
Discussion started by: fitzwilliam
1 Replies

8. Shell Programming and Scripting

Send Remote Commands via SSH with variables

Hi there I found the Command to send commands to other servers like: sv01> ssh user@sv02 'ps -ef' But I cant use Variables from a script i want to execute on another server like: sv01> ssh user@sv02 'cd $SCRIPTHOME' although the variable is set on sv01. How can I run commands on sv02 with... (2 Replies)
Discussion started by: DarkSwiss
2 Replies

9. Shell Programming and Scripting

Variables into SED or AWK and multiple commands

Hello I am hoping you may help. I am not sure how to go about this exactly, I know the tools but not sure how to make them work together. I have two SED commands that I would like to run in a shell script. I would like to take the manual input of a user (types in when prompted) to be used... (4 Replies)
Discussion started by: lostincashe
4 Replies

10. Shell Programming and Scripting

How to put variables commands in config files?

Hi All, Seeking for your assistance on how to put in variables all the commands in /bin config files: /home/test/config_file/config.cfg cat /home/test/config_file/config.cfg ECHO=/bin/echo LS=/bin/lsMain script cat test.sh source=/home/test/config_file/config.cfg ECHO=$ECHO LS=$LS#i... (3 Replies)
Discussion started by: znesotomayor
3 Replies
LAST(1) 						    BSD General Commands Manual 						   LAST(1)

NAME
last -- indicate last logins of users and ttys SYNOPSIS
last [-swy] [-d [[CC]YY][MMDD]hhmm[.SS]] [-f file] [-h host] [-n maxrec] [-t tty] [user ...] DESCRIPTION
The last utility will either list the sessions of specified users, ttys, and hosts, in reverse time order, or list the users logged in at a specified date and time. Each line of output contains the user name, the tty from which the session was conducted, any hostname, the start and stop times for the session, and the duration of the session. If the session is still continuing or was cut short by a crash or shutdown, last will so indicate. The following options are available: -d date Specify the snapshot date and time. All users logged in at the snapshot date and time will be reported. This may be used with the -f option to derive the results from stored utx.log files. When this argument is provided, all other options except for -f and -n are ignored. The argument should be in the form [[CC]YY][MMDD]hhmm[.SS] where each pair of letters represents the follow- ing: CC The first two digits of the year (the century). YY The second two digits of the year. If YY is specified, but CC is not, a value for YY between 69 and 99 results in a CC value of 19. Otherwise, a CC value of 20 is used. MM Month of the year, from 1 to 12. DD Day of the month, from 1 to 31. hh Hour of the day, from 0 to 23. mm Minute of the hour, from 0 to 59. SS Second of the minute, from 0 to 61. If the CC and YY letter pairs are not specified, the values default to the current year. If the SS letter pair is not specified, the value defaults to 0. -f file Read the file file instead of the default, /var/log/utx.log. -h host Host names may be names or internet numbers. -n maxrec Limit the report to maxrec lines. -s Report the duration of the login session in seconds, instead of the default days, hours and minutes. -t tty Specify the tty. Tty names may be given fully or abbreviated, for example, ``last -t 03'' is equivalent to ``last -t tty03''. -w Widen the duration field to show seconds, as well as the default days, hours and minutes. -y Report the year in the session start time. If multiple arguments are given, and a snapshot time is not specified, the information which applies to any of the arguments is printed, e.g., ``last root -t console'' would list all of ``root's'' sessions as well as all sessions on the console terminal. If no users, hostnames or terminals are specified, last prints a record of all logins and logouts. The pseudo-user reboot logs in at reboots of the system, thus ``last reboot'' will give an indication of mean time between reboot. If last is interrupted, it indicates to what date the search has progressed. If interrupted with a quit signal last indicates how far the search has progressed and then continues. FILES
/var/log/utx.log login data base SEE ALSO
lastcomm(1), getutxent(3), ac(8), lastlogin(8) HISTORY
A last utility appeared in 3.0BSD. BUGS
If a login shell should terminate abnormally for some reason, it is likely that a logout record will not be written to the utx.log file. In this case, last will indicate the logout time as "shutdown". BSD
January 21, 2010 BSD
All times are GMT -4. The time now is 04:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy