LinuxQuestions.org
Help answer threads with 0 replies.
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 10-16-2008, 02:41 AM   #1
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Rep: Reputation: 0
Unhappy Help me


Hello All,

I have just shifted from windows to linux(Ubuntu).I am a java developer and have really less idea of bash script.I am working on a project and have to make a bash script which can change the system date from present to past and present to future.

Please help me with the same.I would be really thankful

Thanks and Regards
Mohit
 
Old 10-16-2008, 02:47 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Have you tried reading the man page:
Code:
man date
 
Old 10-16-2008, 02:51 AM   #3
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Unhappy Yes i have

Yes i have tried this,but i am not able to built the script
 
Old 10-16-2008, 03:06 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
In order to change the date, you need root access.

Ubuntu disables the root account by default, therefore to run any commands that need root access you typically use sudo.

The first account that is created on Ubuntu has full sudo rights.

To change the date to 07:00 on 1 Apr, you would need to issue the command:
Code:
sudo date 04010700
This will ask for your password (so that it can check if you are able to run this sudo command)

To have this run as a bash script, you need to enter the command into a file. Make #!/bin/bash the first entry in your file
Code:
#!/bin/bash
###
### Demonstration of bash script to change the date to April Fools Day
###
sudo date 04010700
 
Old 10-16-2008, 03:18 AM   #5
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Smile Thanks a tone

Thanks for the help mate.
I have one more question
Is it possible that i can avoid password when i am running as a different user other then root?
 
Old 10-16-2008, 03:25 AM   #6
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Not from a script.

You are starting to concern me, why are you trying to change the system date?

This should not be done without careful consideration, especially if the machine hosts a database as this would ruin transactional integrety.
 
Old 10-16-2008, 03:31 AM   #7
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Its just because i am finding it hard to change it using java.I am working on a project and it involves activating and deactivating accounts,I have to automate the application for that purpose.
 
Old 10-16-2008, 03:32 AM   #8
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Moreover i am trying this on a test machine.So there should be nothing dangerous i suppose.
 
Old 10-16-2008, 03:51 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Moving the system date back & forth will cause problems. Why do you think you need to do it?
 
Old 10-16-2008, 04:13 AM   #10
mohit7984
LQ Newbie
 
Registered: Oct 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Well Thanks for the help.

I understood your point.
 
  


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




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