Hello I have written a script and I want to schedule it to run at a certain time with the at command. I also want to use an argument in order to pass the time I want in the script so it can be executed at a specific time. The script's name is displaydir and it has the following arguments:

./displaydir dir1 09:00 AM

The script:

at $2 $3
ll $1
cp ./$1/ ./dir2
exit 0

2 Answers 2


From the command line and the script I gather that your want your directory listing to happen at nine AM. This can happen with the following command:

at 9am -f displaydir

with the following script (displaydir):

ll dir1
cp ./dir1/ ./dir2
exit 0
  • Thank you for answering! Is there anyway to make the command line look like this: ./displaydir dir1 09:00 AM Because the hour and the directory have to be arguments
    – user25
    Dec 27, 2019 at 15:19

I have updated your script as follows;

at ${2} <<ENDOFFILE
ls -l $1
cp $1/* $3/
exit 0

Run the script at below;

./displaydir dir1 "09:00 AM" dir2

I have added "*" in the copy command and also taking destination at an argument to the script, you can add -r to cp command if you want to recursively copy everything in that directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.