LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-06-2008, 01:30 AM   #1
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Rep: Reputation: 30
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
 
Old 02-06-2008, 01:39 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,805

Rep: Reputation: 324Reputation: 324Reputation: 324Reputation: 324
And this is homework for which University?
 
Old 02-06-2008, 01:59 AM   #3
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
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?
 
Old 02-06-2008, 04:28 AM   #4
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Rep: Reputation: 36
Please use the code -tags.
 
Old 02-06-2008, 05:01 AM   #5
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
I dint get it....Hows it work?
 
Old 02-06-2008, 08:52 AM   #6
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Rep: Reputation: 31
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.
 
Old 02-07-2008, 12:07 AM   #7
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
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?
 
Old 02-07-2008, 01:22 AM   #8
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Rep: Reputation: 31
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

Last edited by LinuxCrayon; 02-07-2008 at 01:23 AM. Reason: Link error
 
Old 02-07-2008, 04:27 AM   #9
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
Lemme take it as a challenge..Good Inspirational Task
 
Old 02-07-2008, 04:44 AM   #10
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
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.
 
Old 02-07-2008, 05:49 PM   #11
LinuxCrayon
Member
 
Registered: Nov 2007
Location: Georgia, USA
Distribution: FreeBSD
Posts: 274

Rep: Reputation: 31
Quote:
Originally Posted by laucian View Post
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.
 
Old 02-08-2008, 01:58 AM   #12
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
you are right, i don't how but i've missed that..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell script to remove old files based on date WindozBytes Linux - General 12 06-04-2012 02:21 AM
Shell Script.. Date format handling C-RAF. Programming 2 02-14-2006 09:34 AM
JCLs in Mainframes to UNIX Shell Script nirmal.garga Linux - Software 1 02-13-2006 10:48 AM
unix shell script cxy0481 Programming 9 11-20-2005 09:15 AM
Shell Script for Gzipping with date output Junior41180 Programming 1 10-16-2004 07:39 AM


All times are GMT -5. The time now is 10:04 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration