- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2012 02:47 AM
03-08-2012 02:47 AM
shell script help
i want to write a shell script
below is the output file
output
PS 030812 0 182 7
request is the password reset date 030812 is the 8th march 2012
182 days is password age
we need to write a script for all user, when ever user reach 170 days we send one auto reply mail to user, regarding your password expire.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012 10:10 AM
03-09-2012 10:10 AM
Re: shell script help
I have half an answer for you. I put in a test at the bottom of my .profile for when I log in. It is not perfect. It is far from secure. The program does not walk on water, or turn water into wine. It uses basic perl.
Best of all. It works for me. It warns me if my password is close to expiring.
The missing part of your request? The email you want.
The main key to this is the /usr/bin/passwd -r files -s unix_login_name_here
So if my unix login is Billy_bobby_billy_bo_bob, I run
/usr/bin/passwd -r file -s Billy_bobby_billy_bo_bob.
The 86400 is 60 seconds times 60 minutes times 24 hours. I.e. number of seconds per day.
#!/usr/bin/perl use Time::Local; $WARN=14; #___________________________________________________ # todays date #________________________________________________________ ( $T_sec, $T_min, $T_hour, $T_day, $T_mon, $T_year, @junk ) = localtime(); $T_epoch = timelocal( 0, $T_min, $T_hour, $T_day, $T_mon, $T_year); ($T_sec,$T_min,$T_hour,$T_day,$T_mon,$T_year,@junk ) = localtime($T_epoch); $T_mon = $T_mon + 1; $T_year = $T_year + 1900; #print "Today is day $T_day month $T_mon yr $T_year\n"; #__________________________________________ # reset password date R_xxxx #__________________________________________ $CMD="\/usr\/bin\/passwd -r files -s $ENV{LOGNAME} |"; open(COMMAND, $CMD) || die "passwd cmd error"; while ( <COMMAND> ) { ( @line ) = split; if ( $#line == 4 ){ if ( $line[3] < 10 and $line[4] > 50 and $line[4] < 80 and $line[1] eq "PS" ) { # foreach $x ( @line ) { print "x is $x\n"; } # $line[0] name # $line[1] PS # $line[2] mm/dd/yy $dline[0], $dline[1], $dline[2] # $line[3] < 10 # $line[4] < 80 and > 50 @dline = split(/\//, $line[2]); $R_epoch=timelocal( 0, 0, 0, $dline[1], $dline[0]-1, $dline[2]); $R_epoch=$R_epoch + ( $line[4] * 86400 ); ($R_sec,$R_min,$R_hour,$R_day,$R_mon,$R_year ) = localtime($R_epoch); $R_mon++; $R_year = $R_year + 1900; #print "Password day $R_day month $R_mon yr $R_year\n"; #------------------------------ # Dday is the reset required date - warning days #------------------------------ $D_epoch=$R_epoch - ( $WARN * 86400 ); ($D_sec,$D_min,$D_hour,$D_day,$D_mon,$D_year ) = localtime($D_epoch); $D_mon++; $D_year = $D_year + 1900; #print "D-day $D_day month $D_mon yr $D_year\n"; if ( $T_epoch >= $D_epoch ) { print "User $ENV{LOGNAME}, You need to change our password soon.\n"; printf("Today is day %02d/%02d/%04d\n", $T_mon, $T_day, $T_year); printf("Warn day is %02d/%02d/%04d\n", $D_mon, $D_day, $D_year); printf("Password day %02d/%02d/%04d\n", $R_mon, $R_day, $R_year); } else { print "User $ENV{LOGNAME}, "; printf("the day your password dies is %02d/%02d/%04d\n", $R_mon, $R_day, $R_year); } } } } close(COMMAND);
- Tags:
- Perl