Expire license


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expire license
# 1  
Old 10-01-2015
Expire license

I have a program that outputs a file on the number days left before software license expired. It reads in a text file name expiredt.txt.

expiredt.txt contents are as follows:

Code:
EM software          30NOV2015     11/30/2015
ABM software        30NOV2015     11/30/2015
ABM software        30OCT2015      10/30/2015
Publish software    29JUN2016      06/29/2015

I am get error messages. I am new to writing shell script programs.

here are errors I am getting:

Code:
expr: 0402-050 syntax error.
line 22 [: -lt: unary operator expected
line 25 [: -le: unary operator expected
date:Not recognized flag: d
usage: date [-u] [+ "Field Descriptor"]



Code:
#!/bin/bash

# Set expiry file date name to first parameter, default to foo5.txt
EXP_FILE=${1:-expiredt.txt}

# Temp file to take the expired products, if any
OUT_FILE=/opt/SM/expired_license/EXP/license/chkexpire.$$

# Get the current date in seconds since the epoch
now_date=$(date "+%s")

while read exp_line; do
  # Get the expiry date as the last field in the expiry file
  exp_date=$(echo $exp_line | awk '{print $NF}')

  # Convert that date to seconds since the epoch
  exp_seconds=$(date -d ${exp_date} "+%s")
  
  # Work out days to go
  days_to_go=$(expr \( 86399 + $exp_seconds - $now_date \) / 86400)

  if [ $days_to_go -lt 0 ]; then
    ((days_to_go=0 - days_to_go))
    echo PROBLEM: $exp_line expired $days_to_go days ago
  elif [ $days_to_go -le 30 ]; then
    echo $exp_line has $days_to_go days left
  fi
  
done < ${EXP_FILE} > ${OUT_FILE}

if [ -s ${OUT_FILE} ]; then
  # One or more products expiring - report them
  echo "$(cat ${OUT_FILE} | wc -l) Product(s) Expiring"
  cat ${OUT_FILE} | mail -s "$(cat ${OUT_FILE} | wc -l) Product(s) Expiring" j.mj@aol.com
else
  echo File ${OUT_FILE} is empty, so no expired software
fi

rm -f ${OUT_FILE}

Moderator's Comments:
Mod Comment Please use CODE tags for all sample input, sample output, AND for code segments.

Last edited by dellanicholson; 10-02-2015 at 01:25 AM.. Reason: Add CODE tags; change QUOTE tags to CODE tags.
# 2  
Old 10-02-2015
Looks like you copied the script from Linux to some other operating system, and your date command used is not the same as on previous operating system.

Either you will need to install the GNU date or change your script in part related to date handling.

Perhaps an awk strftime will be more common on various OS ?

What is your operating system ?
This User Gave Thanks to Peasant For This Post:
# 3  
Old 10-02-2015
As Peasant said, we need to know what operating system you are using. You are using several features in your script that are not included in the standards (date -d option, date +'%s' format specifier, and ((expression)) arithmetic commands). The awk strftime() function Peasant suggested is also an extension to the standards. None of these are available on some operating systems, some of these are available on some other operating systems, and all of these are available on some other operating systems when using some shells.

It looks like date -d is what is keeping your script from working, but in addition to that, there are many extremely inefficient invocations of external utilities that could easily be replaced by redirections (commonly known as useless uses of cat), replaced by variable expansions (instead of invoking awk), or arithmetic expansions (instead of invoking expr).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Never Expire & Never Lock

Hi There, Actually I'm looking for command in Solaris 11 for the following Command to do User Never Expire. Command to return the user Expire to normal mode. Command to do User Never Lock. Command to return the user Never Lock to normal mode. Please advice .. (1 Reply)
Discussion started by: roooooooooot
1 Replies

2. Shell Programming and Scripting

Software License Expire in 30 days

I wrote code to read a file text with contents of expiration dates and products. The products expire in thirty days and each day an email message is send as a reminder of the number of days left before the license expires. The code generates errors when executed . Here is part of the code.... (2 Replies)
Discussion started by: dellanicholson
2 Replies

3. AIX

Password Expire Message

Does anyone know if the default message displayed when a users password has expired can be changed? I am just assuming the message below is the default one. If so please tell. Using username "justinxx". justinxx@160.23.12.44's password: WARNING: Your password has expired. You must... (2 Replies)
Discussion started by: juredd1
2 Replies

4. Shell Programming and Scripting

Updating the license tag in XML file with new license

Hi All, I have a XML file : System.xml in which I want to update the license tag with the new data from file licence.xml. The content of files is in following format: System.xml: <?xml version="1.0"?> <!DOCTYPE Configuration SYSTEM "SystemVariables.dtd"> <usageConfiguration... (2 Replies)
Discussion started by: Pramod_T
2 Replies

5. Solaris

user to be never expire ..

Hi All, I have Solaris 9 and there is user created in that server called appuser That user should to be never expire.. can anyone advice me how can I modify that user to be never expire thru the command line without using GUI tool. (1 Reply)
Discussion started by: Mr.AIX
1 Replies

6. Shell Programming and Scripting

Expire Command | Need Help

Hi , I am trying to execute the ipl file as below : my $user="iwadmin"; chomp $user; system("passwd -x 29 $user"); The ipl file executes with out any issues when i have logged in as root in solaris .but when when i try to execute the same file with other user id ie iwadmin ,it says... (3 Replies)
Discussion started by: abhishek1979
3 Replies

7. Solaris

Set Password Never Expire

Hello I want to set the password for user never expire through the command line. For your information the box is running under Solaris 8 platform. (2 Replies)
Discussion started by: shamsul
2 Replies

8. Shell Programming and Scripting

Password expire

Hi, Is there any way to find out the UNIX user's password expire date?. It'll we helpful to inform the users to change the password before it get expires.(FYI - I am not having only admin previlege.) (1 Reply)
Discussion started by: sharif
1 Replies

9. Shell Programming and Scripting

Telnet session does not expire

Dear friends.. Our project has a module that runs on handheld devices. Through the handheld we telnet to solaris where the application actually runs. I noticed that after starting a session through the handheld, if i go out of range or if i remove and replace the battery in the handheld, the... (1 Reply)
Discussion started by: deepsteptom
1 Replies

10. UNIX for Advanced & Expert Users

password will expire

login: TEST7 TEST7's Password: Your password will expire: Wed Feb 19 14:28:08 2003 How can I the same information become in a script (as example in the .profile)????????? My login starts with .profile. These File is a menue with 24 lines and the message " Your password ....." disappear to... (8 Replies)
Discussion started by: Erwin Stocker
8 Replies
Login or Register to Ask a Question