Home > Net >  Zabbix who.is domain check script, customizing grep values
Zabbix who.is domain check script, customizing grep values

Time:12-08

**Hello **fellas,

I'm having trouble with my script that connect to who.is website and check if domain is still viable or not. Everything seems to work fine if values that are represented on who.is are typed with slashes 2022/05/05. Problem happens if date is done with dots 2022.05.05 that gives me wrong format.

I'm using script that Kulpin74 made, link to source code: https://github.com/kulpin74/zabbix-ssl/blob/master/externalscripts/whois_expire.sh

I can see it does grep date, but can i postprocess it later: if(grep . replace /) and continue doing script? I think that would solve my problem but couldn't find solution on website.

Thank you for any help :)

Was looking on internet to change . with / but couldn't find solution. Was trying to find other scripts that maybe someone did solve this problem.

CodePudding user response:

To address the problem you are facing, you can use the sed command to search for dates formatted with dots (2022.05.05) and replace them with slashes (2022/05/05) before passing the date string to the date command.

Here is an example of how you can use sed to replace dots with slashes in the expiration_string variable:

# Replace dots with slashes in the expiration_string variable.
expiration_string=$(echo "$expiration_string" | sed 's/\./\//g')

You can then use the date command to convert the expiration_string variable to an epoch time value, as you are currently doing in your script.

Here is an example of how you can use the date command to convert the expiration_string variable to an epoch time value:

expiration_epoch=$(date --date="$expiration_string" ' %s')

After replacing the dots with slashes in the expiration_string variable and converting it to an epoch time value, you can continue with the rest of your script as usual.

I hope this helps!

  • Related