Need help with Linux Case Study !!!!! Just a few questions!!
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ANY HELP WITH THESE QUESTIONS WILL BE APPRIACATED....I have a shell scripting class that has me by the balls and I need to get past the scripting class so I can continue to the Networking and syatem admin stuff.
I need commands to do the following:
I would like to use the SECONDS variable so it will display how long the user is Idle after entering a menu.
How can I tell the oldest & newest files in a directory?
2 different commands!
User Information: a commmand that will display my user name, user ID, Group ID, Group name, Menbers in my group.
In the format of:
User=XXXXXXX user#=XXX group#=XXXX
grp name=XXXXX members=XXXXX,XXXXX
Find files older than 10 days.
Exiting to a sub shell.
ANY HELP WITH THESE QUESTIONS WILL BE APPRIACATED..
Here are some examples to get you started. The find command is simple, use the correct time flag with +10, look t the man page.
Code:
#!/bin/sh
SECONDS_ELAPSED=0
CURRENT_SECONDS=0
LAST_SECONDS=0
# Call TimeStamp before and after what you want to time.
TimeStamp()
{
CURRENT_SECONDS=`date +%s`
SECONDS_ELAPSED=`expr $CURRENT_SECONDS - $LAST_SECONDS`
LAST_SECONDS=$CURRENT_SECONDS
}
TimeStamp
sleep 5 # Prompt for input here
TimeStamp
echo "Seconds: [$SECONDS_ELAPSED]" # Will be 5 seconds
echo "Newest:"
ls -t | head -1
echo "Oldest:"
echo "easy"
ID_OUTPUT=`id`
USER=`echo $ID_OUTPUT | awk '{ print $1 }'`
GROUP=`echo $ID_OUTPUT | awk '{ print $2 }'`
GROUPS=`echo $ID_OUTPUT | awk '{ print $3 }'`
USER_ID=`echo $USER | cut -d'(' -f1 | cut -d'=' -f2`
USER_NAME=`echo $USER | cut -d'(' -f2 | sed 's/)//'`
echo $USER_ID
echo $USER_NAME
# Do the same for group.
# Something similar for groups, but you will have to loop over the
# results since there is an unknown number of them. Use the shell
# favorites: sed, cut, and awk to chop up the results.
Thanks for your help from the other day I'm almost there!
I need to make the #2 option in the menu work. Using the find and more commands.
# this is the GENERIC UTILITIES menu
t=$(date "+%H:%S:%M")
c=$(tput rmso)
dd=$(date "+%b %d %Y")
b=$(tput bold)
while true
do
tput clear
cat << MENU
$LOGNAME GENERIC UTILITIES date - ${b}${dd}${c}
1. ${b}U${c}ser Information?
2. ${b}F${c}ind files older than 10 days
3. ${b}E${c}xit to sub-shell
4. ${b}Q${c}uit menu
User Selection: at ${b}${t}${c}
MENU
tput cup 20 15
read ans
case $ans in
1|U|u) # showuserinfo - print info about user from /etc/passwd and the
#/etc/group
IFS=":" # sets the field seperator to a colon
set -- $(grep $LOGNAME /etc/passwd)
echo "User=[$1] user#=[$3] group#=[$4]"
IFS=":"
set -- $(grep $4 /etc/group)
echo "grp name=[$1] members=[$4]
Press ENTER to continue"
read ans1
;;
2|F|f) #finding files older than n days using- #the find and more commands
#echo "How many day's old?[n]"
#find *.* (???THIS IS WHERE I'M HAVING TROUBLE??)|more
#echo "Please press ENTER to continue"
;;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.