You are not logged in.

#1 2008-01-06 16:40:28

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

[Done] New to scripting - change sysdate/time script

Hi! im trying to make an script to change the date/time in my flux system... using the date command and entering the new date time manually and then the script use that to pass them to the date command, here's what i got now (dont laught too loud tongue), but dont know how to pass the variables to the date command:

#!/bin/bash
echo This script changes system date
echo New Date: (mmdd): 
read date
echo Year (yyyy): 
read year
echo Time (hhmm):
read time
# -- command that set's new date --
date datetimeyear # <---- the date command takes this format as valid mmddhhmmyyyy
echo System date modified successfully
echo --- Press a key to exit ---
read

Last edited by leo2501 (2008-01-06 16:57:49)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-01-06 16:45:46

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: [Done] New to scripting - change sysdate/time script

Dollars is what you want, $date$time$year will do.

Offline

#3 2008-01-06 16:49:21

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: [Done] New to scripting - change sysdate/time script

you need to put quotes around the New Date.... types of lines because of the parens.  Bash needs to know that these are strings.  also when reading in a variable you just use the var name, but when referencing the variable use $varname, so the line would be "date $date$time$year".  also the time variable needs a different name as time is already a keyword.  for reference, 

#!/bin/bash
echo This script changes system date
echo "New Date: (mmdd):" 
read date
echo "Year (yyyy):" 
read year
echo "Time (hhmm):"
read ttime
# -- command that set's new date --
date $date$ttime$year # <---- the date command takes this format as valid mmddhhmmyyyy
echo System date modified successfully
echo --- Press a key to exit ---
read

is what i changed it to, it works, but coding practices probably need some work.  it's nice to see you are learning scripts to make your life easier.  many people just rely on scripts other people wrote to do things for them.

edit: how did i miss the post above me??

Last edited by rson451 (2008-01-06 16:49:56)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#4 2008-01-06 16:57:05

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: [Done] New to scripting - change sysdate/time script

Thank u all!!! i love learning to do everything my way smile that way i do it the way i like and dont the way others like tongue

i forget to add the "sudo" command to the date command:

sudo date $date$ttime$year # <---- the date command takes this format as valid mmddhhmmyyyy


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#5 2008-01-06 18:58:39

Zer0
Member
From: Windsor, ON, Canada
Registered: 2006-08-25
Posts: 299

Re: [Done] New to scripting - change sysdate/time script

Some handy reference guides for scripting can be found at TLDP.org
I always look back at the Advanced Guide when I'm unsure about something.. it's very helpful.

Bash-Beginners-Guide
Advanced Bash-Scripting Guide

Offline

Board footer

Powered by FluxBB