A little C++ program to unlock a LINUX login on Saturdays afternoons follows. All suggestions are welcome.
#include <cstdlib>
#include <ctime>
#include <sstream>
/// av[0] USERNAME
/// to unlock between 12:00 and 19:59 on Saturdays.
int main(int ac,char** av)
{
if( 2 == ac )
{
const std::time_t now( std::time(NULL) );
const std::tm* timeinfo = std::localtime( &now );
std::ostringstream cmd;
cmd << "/usr/sbin/usermod -";
if( timeinfo->tm_wday == 6
&& timeinfo->tm_hour > 11
&& timeinfo->tm_hour < 20 )
{
cmd << 'U';
}
else
{
cmd << 'L';
}
cmd << ' ' << av[1];
std::system( cmd.str().c_str() );
return EXIT_SUCCESS;
}
else
{
return EXIT_FAILURE;
}
}
This blog is all about issues related to the business of the company
0 kommentarer:
Post a Comment