When the cron execute your job, it does so in an environment that is not the same as your current shell environment.
This means, for example, that
./script.sh may not be found.
There are two solutions:
*/1 * * * * ( cd $HOME/mydir && ./script.sh )
*/1 * * * * $HOME/mydir/script.sh
I.e., specify exactly where the script may be found.
The first alternative may be preferable if you don't use absolute pathnames for the output file within the script.
If you go with the second option, modify your script so that you know where the output file goes:
echo "$USER" >"$HOME/mydir/cron.txt"
( cd "$HOME/mydir" && echo "$USER" >cron.txt )
Notice that the
#! line has to contain the correct absolute path to
bash (your's was a relative path).
It should also be noted that cron on some Unices (Linux) do not set
USER to the username of the user running the cron job. On these systems, use
$LOGNAME instead, or set
$LOGNAME when invoking the script:
*/1 * * * * env USER=$LOGNAME $HOME/mydir/script.sh