In my system using cron.d there is a file which is repeatdly run. It generates an answer to my exercise.
I used ls /etc/cron.d I have access to this file.
It is alice.sh I use
Code:
sh /tmp/tmp.6vOX6HxEg1/alice.sh
my resposne
Code:
alice@ip-10-0-119-57:~$ sh /tmp/tmp.6vOX6HxEg1/alice.sh
cat: /root/archive/secret.txt: Permission denied
/opt/create_and_delete_file_from_args.sh: line 7: /tmp/tmp.6vOX6HxEg1/151504505d2d29ecad318671b5476560: Permission denied
rm: cannot remove '/tmp/tmp.6vOX6HxEg1/151504505d2d29ecad318671b5476560': No such file or directory
It generates a file that I need to read but it is as I read deleted.
I was thinking to run my own script which will listen and copy all kind of files when created to another directory. But I am green I do not know how to write own listener in bash linux.
Thanks in advance.
this is alice.sh
Code:
#!/usr/bin/env bash
secret_script_path="/opt/create_and_delete_file_from_args.sh"
secret_directory="/tmp/tmp.6vOX6HxEg1"
secret_file="TUApZ7WH3C7n"
bash "${secret_script_path}" "${secret_directory}" $(echo "${secret_file}" | md5sum | awk '{ print $1 }')
first edit:
this next .sh file has got a method that create and after 0,005s delete file with information.
EDIT:
This is my /opt/create_and_delete_file_from_args.sh file
Code:
#!/usr/bin/env bash
"secret_directory=$1
secret_file=$2
exercise_flag=$(cat "/root/archive/secret.txt")
echo "${exercise_flag}" > "${secret_directory}/${secret_file}"
sleep 0.005"
rm "${secret_directory}/${secret_file}"
I can't edit this file it is only readable I wanted to delete rm and add cat after creating.
There was an idea to create another .sh file without rm and with cat, but I can't do it.
After leaving vim I used
Code:
:w !sudo tee % > /dev/null
but there is error with
Code:
Username is not in the sudoers file. This incident will be reported
if I'm leaving with :w then "E212 Can't open file for writing"