Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory

 if [ -f report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ]
then
        mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly
        mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly
            ${LOCL_WORKING_DIR}/sftp_ondemand_monthly.sh /export/applications/ibm6000/mbsesb/config/ondemand.cfg /export/applications/ibm6000/mbsesb/config/filename.lst
else
        echo "There is no report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv file ${Today}"
fi

Strange, but the directory is not created
Could you please let me know what is wrong with my script?

Thanks for contribution

Hello digioleg54,

I have a few to questions pose in response first:-

  • What have you tried so far to diagnose this?
  • Where is variable LOCL_FILES_DIR set?
  • Where is variable Today set?
  • What output/errors do you get?
  • What OS and version are you using?

Most importantly, What have you tried so far?

There also seems to be a split line, so you have an echo that will look rather ugly.

We're all here to learn and getting the relevant information will help us all.

All variables are set up. Now it creates monthly directory and moves files
But this script:

 ${LOCL_WORKING_DIR}/sftp_ondemand_monthly.sh /export/applications/ibm6000/mbsesb/config/ondemand.cfg /export/applications/ibm6000/mbsesb/config/filename.lst
 

Doesn't start. It exists on ${LOCL_WORKING_DIR}/

have you tried adding set -x to the script and tracing its execution?
I can see a potential issue with -f report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv statement...

No, I put print statement inside. I goes inside if statement, prints everything, but doesn't start the script

 if [ -f report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ]
then
        echo "We are in report" >> ${LOGF}
        mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly
        mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR
}/cool_${Today}/monthly
        echo "Before sftp_ondemand_monthly.sh">>${LOGF}
        echo "${LOCL_WORKING_DIR}/sftp_ondemand_monthly.sh /export/applications/
ibm6000/mbsesb/config/ondemand.cfg /export/applications/ibm6000/mbsesb/config/filename.lst" >>${LOGF}
        ${LOCL_WORKING_DIR}/sftp_ondemand_monthly.sh /export/applications/ibm600
0/mbsesb/config/ondemand.cfg /export/applications/ibm6000/mbsesb/config/filename.lst
        echo "After sftp_ondemand_monthly.sh">>${LOGF}
else
        echo "There is no report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv file ${Today}"
fi

OUTPUT

 We are in report
Before sftp_ondemand_monthly.sh
 
/export/applications/ibm6000/mbsesb/sh/sftp_ondemand_monthly.sh /export/applications/ibm6000/mbsesb/config/ondemand.cfg /export/applications/ibm6000/mbsesb/config/filename.lst
 
After sftp_ondemand_monthly.sh

No error messages, nothing

I'd suggest adding set -x to the "master" script and to the /export/applications/ibm6000/mbsesb/sh/sftp_ondemand_monthly.sh script to trace their execution. This makes tracing much easier and will "flag" any potential issues with variable expansion and/or test statements...

I put it. No errors messages. Just don't execute

 ondemand_sftp_monthly.sh
 

strange, your version of the script mentions /export/applications/ibm6000/mbsesb/sh/sftp_ondemand_monthly.sh and not ondemand_sftp_monthly.sh .
Does the enabled tracing help identifying a potential issue?
Saying Just don't execute isn't really helpful....

Found problem. thanks everybody.
forgot to put

  echo ".......
 

the other double quote

---------- Post updated at 01:17 PM ---------- Previous update was at 01:12 PM ----------

Don't think so. Shell languages don't silently skip statements, so either your script is run (and you didn't notice it) or you get an error (and you didn't notice it).

I would like to see again

  • The content of the script you are debugging
  • The way you are invoking it
  • The complete output of the run with -x

For example you could do a

cat yourscript.sh
bash -x yourscript.sh

and post here a link to, for instance, a screenshot of the result.