I need to find first daty of each month. What will I see on AIX "1" or "01"

Could you please let me know the following? I have to find and check first day of each month. I do

 fdt=`date +%d`
 

will it give me on AIX

 "1" or "01"
 

I ask you because I couldn't make real test on first day and don't know

Thanks for contribution

 fdt=`date +%d`
 
if [ $fdt -eq 1 ] ; then
    echo 'today is first day of month'
   
else
   echo 'today is not first day of the month'
fi 

I am pretty sure this is not what you need. You need to explain what you want to accomplish. NOT how you want to do it. Why do I say this? Because the correct answer I gave is not very useful.

I need on the first date of each month run the program, which is supposed to run first day of each month.

on AIX

 if [ $frst -eq 1 ]
 

will not work. It should be something like

 if [ "${frst}" = "1" ]
 then
       run the program
 else
      echo "Not the first date
 fi
  
 or 
  
 if [ "${frst}" = "01" ]
 then
       run the program
 else
      echo "Not the first date
 fi
  
 

I am not sure what it returns 1 or 01

What I gave you will work in most shells, 01 does test as numeric 1.
Bash example:

$ f=01
$ echo $f
01
$ [ $f -eq 1 ] && echo 'works'
works

ksh example

$ f=01
$ echo $f
01
$ [ $f -eq 1 ] && echo 'works'
works

You may have to use something like

typeset -i frst

to force the frst variable to evaluate as an integer, in some old shells.

Since I do not know either your shell or its version I cannot help you any more than that.

Anyway, why do you not create a cronjob that executes on day one of any month?
crontab -e lets you edit your crontab
Ex: run at 10:10 only on the first

10 10 1 * *  /path/to/my/program.shl

Wouldn't this be easier done using a cron-job?

1 Like