1

I have a command job on autosys that should execute a bash script to rename several files in a specific directory. My script has this:

for x in /opt/testing/fileToRename*.xls;
do mv "$x" "newName.csv";
done

When I run the script directly from the shell everything works fine, also if I take the command and run it directly from the shell it works, but when I try to run it from the command attribute of my job, this job only deletes all the files in the path but not rename the file. Just to clarify, the user I am using in the owner attribute of my job is the same I am using in the shell.

Someone can help me?

Gaudy Blanco
  • 41
  • 1
  • 4
  • 1
    You are renaming all files to the same name, `newName.csv`, as per the code you have posted here. This is the equivalent of removing all but the last file. – codeforester Jan 17 '18 at 17:40
  • That's exactly what I need. The problem is the job deletes all files, I need to keep the last file. – Gaudy Blanco Jan 18 '18 at 23:35

1 Answers1

0

Use full path for new file , when autosys runs your script as your user it does not run it in /opt/testing/ most likely it puts new file in $HOME of the user or $HOME directory of the agent and that's why perhaps you can't find newName.csv . The $x contains full path to your file though , so the deletion works , but renaming goes into different folder.

for x in /opt/testing/fileToRename*.xls;
do mv "$x" "$(dirname "$x")/newName.csv";
done