Results 1 to 3 of 3
I'm puzzled at why it doesn't work. I'm probably missing something really simple.
Code:
#!/bin/bash
if [ ! $# == 1 ]; then
echo "Usage: You need to provide exactly ...
- 07-18-2009 #1Linux Newbie
- Join Date
- Feb 2009
- Posts
- 100
who / lastlog script not working
I'm puzzled at why it doesn't work. I'm probably missing something really simple.
Basically, neither who nor lastlog gets executed. I edit it in vim and all the commands are automatically highlighted orange (echo, grep, tr, cut, etc) apart from 'who' and '/usr/sbin/lastlog'.Code:#!/bin/bash if [ ! $# == 1 ]; then echo "Usage: You need to provide exactly one argument" else if grep ^$1 /etc/passwd > /dev/null then echo "$1 exists" who | grep $1 else echo "$1 doesnt exist" /usr/sbin/lastlog | grep $1 | tr -s " " | cut -d" " -f6 fi fi exit 0
Any hint? thanks
- 07-19-2009 #2
I think the commands do get executed, but that there is a problem elswhere in the flow of the script.
Code:#!/bin/bash if [ ! $# == 1 ]; then echo "Usage: You need to provide exactly one argument" else if grep ^$1 /etc/passwd > /dev/null then echo "$1 exists" # This will only give output if $1 is a currently logged in user: who | grep $1 else echo "$1 doesnt exist" # This will only give output if the user account doesn't exist /now/ # but did at one time exist and has logged in then: /usr/sbin/lastlog | grep $1 | tr -s " " | cut -d" " -f6 fi fi exit 0Can't tell an OS by it's GUI
- 07-19-2009 #3Linux Newbie
- Join Date
- Feb 2009
- Posts
- 100
Thanks
Before I wrote it I created dummy users and logged them in as well to see if it worked. For some bizarre reason it works now (who | grep ...). As for the lastlog part, you're right it would never produce anything anyway.


Reply With Quote