LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-30-2001, 08:11 AM   #1
clarkebar
LQ Newbie
 
Registered: May 2001
Posts: 5

Rep: Reputation: 0
Exclamation


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..




 
Old 05-30-2001, 10:27 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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.
 
Old 05-31-2001, 07:45 AM   #3
clarkebar
LQ Newbie
 
Registered: May 2001
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up Thank you

I'm gonna give this code a run tonight. Thank you, very much.
A person in need
 
Old 06-01-2001, 08:54 AM   #4
clarkebar
LQ Newbie
 
Registered: May 2001
Posts: 5

Original Poster
Rep: Reputation: 0
Exclamation I'm almost there....need just alittle more help

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"
;;

3|E|e) bash; continue
;;

4|Q|q) exit
;;


esac
done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to study linux sake Linux - Newbie 7 11-08-2005 06:29 AM
linux study... os2 General 4 11-04-2005 05:54 PM
Case & sound card related upgrade questions Proud Linux - Hardware 3 12-20-2004 06:36 PM
Case Study For Linux OS varunbihani Linux - General 3 11-08-2003 02:51 AM
Case Study Please help!!!! I'm almost there clarkebar Programming 0 06-01-2001 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration