I am writing a script to check the password age for a given user. At the moment the script is interactive and once I have it working as desired I will make it so that it is fully automated.

The issue that I am running into at the moment is that I will deploy it across different versions of Unix/Linux.

I have an if statement that will check if the system is Linux/AIX and depending on the results I want to run certain commands.

If you take a look at the script, I have a variable such as DAYS. If I run this variable inside an if statement, I simply get an error and it fails.I also tried making the DAYS variable into a function, however the results are the same.

What do I need to do to get this to work so that I don't have to type the whole variable inside the if statement as shown below?

My description may not be as well as I would like it to be, but please let me know if you have any questions?

This is what I have so far. When I run this on Linux it works like a charm.

However, I am still sorting out some issues on AIX. I hope that someone can take this and use it or make it better. I will continue posting until the script is finished and fully functional, well, it kinda is now.

What sort of issues are you having on AIX? I don't have access to an AIX shell at the moment, but I used to do a lot of cross *nix scripting. Stuff that had to work on Linux, AIX, HPUX, and Solaris...

Hi jeo-

Thank you for asking. I am not that familiar with AIX and the passwd file in /etc/security. When trying to calculate the password age using the lastupdate number for a given user I don't know what that number means if days, seconds, weeks, so I am working on that at the moment. But this script will need to work on AIX, Linux, HPUX, Solaris.

Ok, I just learned this is in seconds since EPOCH time. -->

-----------------------------------------------------------------

I just updated the script and *believe* to have it working in AIX.

I just converted the lastupdate time which is set to EPOCH time in seconds to EPOCH days.

Again, thank you Watael. Simply changing from single to double quotes the function AIX is working properly.

I've decided not to do HPUX because it sucks. Not really, I just don't have access to HPUX at the moment so I am just leaving this here in hope that someone can use it as the base for a better script or let me know how it can be improved.

Code:

#!/bin/sh#set -x

HOST=`uname -n`MAX=30SYS=`uname`

###--- Function to check password age for the root account on Linux systems.LINUX (){ USER_ID=`id -u`

#--- Need root permissions to run script if [ $USER_ID -ne 0 ]; then echo "Must be root to run this script!!" exit 2 fi

#--- Get the user's name to query the password age. echo "Enter the username:" read USER

Who is online

Users browsing this forum: No registered users and 16 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum