There are several problems here. The one that's causing the immediate problem is that at
reads the commands to run from its standard input, and that's not (generally) the script. Generally the simplest way to feed input to a command in a script (as its standard input) is a here-document, like this:
command <<EOF-MARKER
input
more input
EOF-MARKER
nextCommand
The next problem is that the cp
command is being asked to copy a directory, but hasn't been passed the -R
option, so it'll refuse to do anything. I think you probably want cp ./$1/* ./dir2
to copy the files in the directory, rather than the directory itself.
I'm not sure about this, but if ll
is an alias, it may not work in the at
job (since aliases are generally disabled in non-interactive shells). I'd recommend using the full command (probably ls -l
).
Next, the output from the job will be emailed to you. Or at least, it'll try to email it to you; it might or might not do anything useful. If you want the output to go somewhere predictable, you should redirect it yourself.
Finally, if the directory name $1
has any funny characters in it, using it without quotes will cause trouble. (I work mostly on macOS, where filenames with spaces are very common, so I'm ... aware of this issue.) Normally, the best way to handle this is to double-quote the parameter reference, but in a here-document single-quotes are more likely to work (unless the name might itself contain single-quotes).
So, here's what I get for the corrected script:
#!/bin/bash
at $2 $3 <<EOF
ls -l '$1'
cp ./'$1'/* ./dir2
exit 0
EOF