Script for sending date and time to a user on the network
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.
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.
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.
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.
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 ?
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"
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.