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 08-31-2013, 08:41 PM   #1
Grimlox57
LQ Newbie
 
Registered: Aug 2013
Location: Canton Ohio
Posts: 4

Rep: Reputation: Disabled
Script for sending date and time to a user on the network


I'm currently taking a Linux network admin class and it been over a year since command line class. My current homework requires a shell script that sends the date and time to a user logged on to the network. It also must log the time and date and user it was sent to. Any help would be great as I'm very lost atm.
 
Old 09-01-2013, 02:48 AM   #2
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
great so you are here to do your homework !!
well we could help you but only in a case you try something from your side first.
they have given you a home work only after letting you know about some of the basics, so apply them and try to create some script based on that atleast try to built a logic. we will help you get clear on it untill you can make something out of it yourself.

one more thing we at LQ dont support giving all the cooked stuff, you have to try something on your own to get the help here.
 
Old 09-01-2013, 03:55 AM   #3
Grimlox57
LQ Newbie
 
Registered: Aug 2013
Location: Canton Ohio
Posts: 4

Original Poster
Rep: Reputation: Disabled
If I knew where to even start with this I wouldn't of asked for help. The book I have for the class does not cover scripts, and the teachers power points has no commands or even a example script to even give me a idea where to start. I'm current digging though notebooks of the command line class trying to find anything I can use. I have never wrote a Linux script before. I'm not asking for people to do it for me just need pointed in the right direction.
 
Old 09-01-2013, 05:00 AM   #4
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
Quote:
I'm currently taking a Linux network admin class and it been over a year since command line class.
You want to say after a year over or command line class you are not able to find out where to start.. OK i take this as corect but atleast show something you have google give it a try .. Start over

I dont understand what your teachers are doing when they didnt even taught you anything how they are giving assignments ?
 
Old 09-01-2013, 06:26 AM   #5
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by Grimlox57 View Post
I'm currently taking a Linux network admin class and it been over a year since command line class. My current homework requires a shell script that sends the date and time to a user logged on to the network. It also must log the time and date and user it was sent to. Any help would be great as I'm very lost atm.
How do you plan to get the date/time?

How will you know if a user is logged in (presumably on a remote system)? How could you determine if a user is logged into your system?

What are some protocols that can be used to send information from one system to another?

When you log information, that typically infers that the information will be written to a file. Has your instructor given you other requirements?

In summary... break your assignment into smaller problems, then try to collate the individual solutions of each to formulate a complete solution for the assignment.

A typical shell script in Bash would look like:
Code:
#!/bin/bash

echo "This is a shell script"

exit 0
Possible suggestions for Google searches:

"Linux get date time"
"Linux list logged on users"
"Linux send data to another system"
 
Old 09-01-2013, 08:26 AM   #6
mariostg
Member
 
Registered: Apr 2011
Location: Gatineau, Quebec
Distribution: OpenBSD
Posts: 80

Rep: Reputation: 5
@Grimlox57
I must agree with what people have replied so far. In addition to what dwhitney67 wrote, there is always the good old Linux documentation project.. There you might want to look at the Advanced Bash-Scripting Guide
 
Old 09-01-2013, 02:28 PM   #7
Grimlox57
LQ Newbie
 
Registered: Aug 2013
Location: Canton Ohio
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the links and the small script. least I got somewhere to start now. Here the exact question that's on the lab I was given:

1.Create a shell script called send_date.bash ◦The script is to send the current date and time to a user currently logged on to the system
◦The user to receive this date will be specified as the first argument on the command line
◦Remember, All scripts must have comments documenting purpose, who, when, etc.
◦This script must log the time and user this date was sent to.

2.Test the script, if necessary, logon a second time yourself to test.
3.Document this newly created script using j --list send_date.bash > ~/lab01/lab01.step08.html with appropriate description

breaking it down in sections will help a lot.ill need to use the who command to find if someone is online. then output the time date to them while also logging it. least I think im pointed in the right direction now. JUst need to find the commands and get them in the right order.

Before I took this class other students in the network program said this class is hard cause half the time you have no clue what to do. The professor basically does nothing but says here do this with very little instruction and very little notes. The command line class touched on scripts very little it was more file commands sed grep stuff like that. What ive googled so far just confused me more. I'm not the only one in the class having problems with it. least 5 other students in the class been messaging me asking if I figured any of it out yet.

ill try and post a rough script soon.

oky this what I have so far

#!bin/bash/
#description of script
echo "$date" | write $1
$1 $date > ~/lab01/datelog
exit 0

Last edited by Grimlox57; 09-01-2013 at 05:07 PM. Reason: added code
 
Old 09-01-2013, 08:44 PM   #8
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
Quote:
#!bin/bash/
#description of script
echo "$date" | write $1
$1 $date > ~/lab01/datelog
exit 0
ok good to see atleast you tried a bit.

So here's a tip:
1. whenever you are writing any script, test the commands first, if they are working or not.
2. after writing the script do not assume it as correct untill you test it.

The above you wrote wont work at all... but will give you error.

Quote:
echo "$date" | write $1 # will echo $date on the users tty and not the "date"
did you ever tried echo "$date" on your machine ? well date as a variable is defined as "$(date)"

Quote:
$1 $date > ~/lab01/datelog # will create an empty file named "datelog" and give an erro too
define the date variable correctly, and then make a use of echo to redirect it to the datelog file.

Code:
$(date)    # is a good use of date command
always validate for the arguments when your scripts has a requirement of one.

Code:
 if [[ -z $1 ]]; then     # check if any argument is supplied or not.
echo "[Usage]:  $0 [args1]"     # if not print Usage.
exit 1                          # set the exit status.
fi
last but not the least..
Quote:
#!bin/bash/ # is a wrong declaration
#!/bin/bash # is a correct one

Be sure to test your script first and then post, that ways you will be able to unlock more questions and find more efficient ways.

Last edited by SAbhi; 09-01-2013 at 11:27 PM.
 
Old 09-01-2013, 10:42 PM   #9
Grimlox57
LQ Newbie
 
Registered: Aug 2013
Location: Canton Ohio
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the help had to turn it in before the timer locked me out of the homework. I never did get it to send anything to the log file. I went as far as emailing the professor twice still no reply. This is the first week of class I hope it gets better.
 
  


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
Each time a script is called. A log file is created with time and date + Bash Script. y0_gesh Programming 6 08-17-2012 03:16 AM
Script shell - Date / Time doint Programming 4 04-12-2012 09:09 AM
Run script once at certain date and time winairmvs Linux - Software 4 03-18-2010 05:04 PM
Shell Script - Date/Time runnerpaul Programming 9 08-20-2008 07:45 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM

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

All times are GMT -5. The time now is 04:49 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