LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Script for Unix Date ??? (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-for-unix-date-618994/)

ajeetraina 02-06-2008 12:30 AM

Shell Script for Unix Date ???
 
I need one shell script to change unix machine date ..

That script will take date as command line argument

Login and password should be hard coded in the script

Pls Help

bigrigdriver 02-06-2008 12:39 AM

And this is homework for which University?

ajeetraina 02-06-2008 12:59 AM

I am sorry if this is an easy questions...Will be thankful if you help me..Let yu tell myattempt:
echo –n “login”

sty -echo

echo -n "Password: "

stty -echo

read passwords

#tty echo

#echo "" # force a carriage return to be output

correct="$(cat /etc/verify)"

if [$password = $correct] ; then

echo “Enter the Year”

read y

echo “Enter the month”

read m

echo “Enter the Day”

read d

echo “The Date modified is $m-$d-$y”

else

failed=$((failed + 1))

Does the Concept sounds Good?

Zmyrgel 02-06-2008 03:28 AM

Please use the code -tags.

ajeetraina 02-06-2008 04:01 AM

I dint get it....Hows it work?

LinuxCrayon 02-06-2008 07:52 AM

You don't need to do a "force carriage return", by the way. \n works well I find. Also, you're not actually changing the date. You're just outputting that you are.

What Zmyrgel meant is to enclose your code in [ code ][ /code ] tags, without the spaces between the brackets and the letters. For example, here is your code in code tags:

Code:

echo –n “login”

sty -echo

echo -n "Password: "

stty -echo

read passwords

#tty echo

#echo "" # force a carriage return to be output

correct="$(cat /etc/verify)"

if [$password = $correct] ; then

echo “Enter the Year”

read y

echo “Enter the month”

read m

echo “Enter the Day”

read d

echo “The Date modified is $m-$d-$y”

else

failed=$((failed + 1))

Also, if this is homework, it's against forum rules to ask for help for homework.

ajeetraina 02-06-2008 11:07 PM

Okies...I got a point that code should be enclose within the code.
But why yu people are really not ready to help me out with this?

Pls Help me with this shell script?
I tried but couldnt help myself?

LinuxCrayon 02-07-2008 12:22 AM

We aren't very willing because it sounds an awful lot like homework. Additionally, the first page under a Google of "change linux date" reveals the answer...which might be another reason someone's not too willing. A 'man date' command would probably give you the answer, in fact! It's rather obvious that you've tried to rely on your existing knowledge to fix the problem, then asked for help without looking first.

Sorry to sound harsh, but the rules say no homework help. And generally you should try to find the answer on your own before asking.

Additional places you could've looked:

LinuxQuestions Wiki
Forum search

After learning and understanding the information, it should be trivial to use variables to set the date.

Google - It's Your Friend

ajeetraina 02-07-2008 03:27 AM

Lemme take it as a challenge..Good Inspirational Task

laucian 02-07-2008 03:44 AM

are you a programmer, are you asking help because you need help with shell script?

i can see helping with the homeworks is against the rules, otherwise it would break the whole education system..but maybe i can give you start..

first of all look for a bash scripting tutorial and write a small hello world example. if you are a programmer you would understand the syntax quickly.
Then get a little bit deeper and learn how to manipulate variables, functions, I/O. After getting an abstract idea of the scripting language google for the functions you need. how to change the date, how to read user name etc..

final part is obvious..just combine them..write your code..if you then have problem, and you post your code, i think(not 100% sure:) ) you will get help as it is no more your homework but a spesific question.

LinuxCrayon 02-07-2008 04:49 PM

Quote:

Originally Posted by laucian (Post 3048846)
are you a programmer, are you asking help because you need help with shell script?

i can see helping with the homeworks is against the rules, otherwise it would break the whole education system..but maybe i can give you start..

first of all look for a bash scripting tutorial and write a small hello world example. if you are a programmer you would understand the syntax quickly.
Then get a little bit deeper and learn how to manipulate variables, functions, I/O. After getting an abstract idea of the scripting language google for the functions you need. how to change the date, how to read user name etc..

final part is obvious..just combine them..write your code..if you then have problem, and you post your code, i think(not 100% sure:) ) you will get help as it is no more your homework but a spesific question.

He's already shown that he has at least SOME understanding of scripting/BASH. In fact, he's only missing MAYBE two or three lines from his example.

laucian 02-08-2008 12:58 AM

you are right, i don't how but i've missed that..


All times are GMT -5. The time now is 12:28 AM.