I am by no means an expert in Linux (Debian) so, please try not to hysterically laugh at my "problem"...
I have a Raspberry Pi that will ultimately be somewhere on a network with no Internet access, only LAN, and with no human interface like a
screen/mouse, etc.
So, I want the ability to set the Pi's Date and Time using a simple browser and some PERL/cgi script. The Pi has Apache2 on it, and I run other
configurations with the same method without hassle...
But I simple cannot set the date/time.
Here is what I've got so far:
#!/usr/bin/perl -wU
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type:text/htmlnn";
$datestring = localtime();
print "Local date and time $datestringn";
print "< p >";
system('sudo date -s "Thu Aug 9 21:31:26 UTC 2012"');
print "< p >";
$datestring = localtime();
print "Local date and time $datestringn";
print "< p >";
So basically. We've got the bash, allowing unsafe code (I know, I know. Security is not my main issue now), then I get the local time, print it to the
browser screen, then the important part: Use a system call to set the date (the exact date is not important right now) as I would on a terminal, and
then get and show the date/time again to see if it was changed.
When I hit the script with my browser it shows the two dates just fine (i.e. no errors):
Local date and time Thu Dec 18 13:44:22 2014
Local date and time Thu Dec 18 13:44:22 2014
However if I look at the Apache error log I see this:
sudo: no tty present and no askpass program specified
After some Googling, the common solution is:
ssh -t remotehost "sudo command"
However with all the " and ' in the string it looks like this:
system('ssh -t 127.0.0.1 "sudo /root/date -s "Thu Aug 9 21:31:26 UTC 2012""');
And this completely confuses the server/debugger. I get about half a page of errors.
So, what is the very obvious fact I'm missing, or is there an alternative way to set the system date/time?
Edit: I know the < p > tags are incorrect - the board code is preventing them from showing as they should be.
edit on 18/12/2014 by Gemwolf
because: (no reason given)