It looks like you're using an Ad Blocker.

Please white-list or disable AboveTopSecret.com in your ad-blocking tool.

Thank you.

 

Some features of ATS will be disabled while you continue to use an ad-blocker.

 

Some PERL/cgi script help needed

page: 1
1

log in

join
share:

posted on Dec, 18 2014 @ 07:57 AM
link   
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)




posted on Dec, 18 2014 @ 08:23 AM
link   
There is a super awesome and active Rasberry Pi forum on google+ them guys there can probably help u out a ton. I have a rasberry Pi as well except I never opened mine yet however before I bought it I went there fact finding and what not and them people helped me a whole lot in helping me decide to purchase or not.



posted on Dec, 18 2014 @ 09:15 AM
link   
I recommend reading this article, and posting your issue on Stackoverflow in case you encounter further issues.

CLICK



posted on Dec, 18 2014 @ 09:30 AM
link   
a reply to: Brotherman

Thanks - I thought I'd try the brilliant minds on ATS first before moving on to greener pastures... I'll keep them in mind.

a reply to: H1ght3chHippie

Thanks for the link. That's actually where I got the idea for this line of code as per above:

system('ssh -t 127.0.0.1 "sudo date -s "Thu Aug 9 21:31:26 UTC 2012""');


But the problem is that the compiler isn't happy with all the apostrophes and quotation marks. I tried several variations of the above script, and tested several apostrophe formats that is typically used in other programming languages (like doubles and triples and even ASCII characters), but to no avail...


The first prize would be to use a PERL command to change the system date, then I won't have to bother with terminal commands, but I've searched up and down PERL DateTime Object, but can't find a command to set the datetime. And the DateTime::Set doesn't set the system DateTime. But then again, I'm a PERL n00b, so I may just be missing the obvious.
edit on 18/12/2014 by Gemwolf because: (no reason given)



posted on Dec, 18 2014 @ 09:32 AM
link   
a reply to: Gemwolf

Just trying to help you cultivate some options hope it works out for you soon!



posted on Dec, 18 2014 @ 10:55 AM
link   
a reply to: Gemwolf



The first prize would be to use a PERL command to change the system date,


Why not use NTP?

NTP - Debian Wiki

How can I keep system time



P.S. I'm on a Debian system now.


edit on 18-12-2014 by Bybyots because: . : .



posted on Dec, 18 2014 @ 10:55 AM
link   
a reply to: Gemwolf

Hope it helps, I have no access to a Linux system at the moment but it was one of the first hits and leads to Ubuntu, which is Debian based.

date command syntax

Good luck!



posted on Dec, 18 2014 @ 01:52 PM
link   
a reply to: Bybyots

a reply to: LightSpeedDriver

Thanks guys. I'll take a closer look at your suggestions tomorrow at the office when I've got the Pi with me.

However I've got a feeling that I won't have joy.

The Pi won't be on the Internet otherwise an NTP would've been the ultimate solution. (As far as I know the Pi default installation is already set to get its time from an NTP server.) The thing is the Pis will be "out in the field" and often be powered down because of power failures. They tend to loose their date/time after a power down. I suppose if it's really an issue I could set up a Pi on the network on a battery to act as NTP server. But the whole purpose of the set-up is cost-effectiveness, and adding another Pi and battery will make a dent in the budget.

@LightSpeedDriver - that's basically the command I'm currently trying to use. The one in your link is slightly different, and I'll give it a try.


Thanks again for the help. Keep the ideas coming please!



new topics

top topics



 
1

log in

join