-1

enter image description here

I came across very different problem yesterday. I am trying to execute log_path_only.txt by using this command "sh -e log_path_only.txt", It seems to be executed however it is not. I am expecting command line execute log_path_only.txt to remove these static files according to log_path_only.txt once I execute this file. I am using shell as a root and all files permissions is seems to be belongs to root.

log_path_only.txt contains only these lines not anything else
rm -rf /home/mywebsite/www/staticfiles/static-003ae2a3f686d43ec5c3207ec0ae744b-003ae2a3f686d43ec5c3207ec0ae744b-c23c5fbca96e8d641d148bac41017635
rm -rf /home/mywebsite/www/staticfiles/static-00e937fb20315addd5008ebb76134e7e-00e937fb20315addd5008ebb76134e7e-c23c5fbca96e8d641d148bac41017635
rm -rf /home/mywebsite/www/staticfiles/static-00edf2d8a63f1cdc9580092629f580cb-00edf2d8a63f1cdc9580092629f580cb-c23c5fbca96e8d641d148bac41017635
rm -rf /home/mywebsite/www/staticfiles/static-00f1cea6b137132172ad8ea6fc90ab0d-00f1cea6b137132172ad8ea6fc90ab0d-c23c5fbca96e8d641d148bac41017635



[root@www uploads]# ls -l
total 464
-rw-r--r-- 1 root root      0 Oct 19 11:30 148bac41017635
-rw-r--r-- 1 root root      4 Oct 19 11:34 counter.txt
-rw-r--r-- 1 root root  34488 Oct 16 00:15 file_source.txt
-rw-r--r-- 1 root root 204521 Oct 19 11:32 log_both_path_urls.txt
-rw-r--r-- 1 root root  80625 Oct 19 11:32 log_links_only.txt
-rw-r--r-- 1 root root 131184 Oct 19 11:32 log_path_only.txt

[root@www uploads]# sh -e log_path_only.txt
[root@www uploads]#

(I try first static file if its there, yes it is. It is supposed to be deleted)

[root@www uploads]# [ -f /home/mywebsite/www/staticfiles/static-003ae2a3f686d43ec5c3207ec0ae744b-003ae2a3f686d43ec5c3207ec0ae744b-c23c5fbca96e8d641d148bac41017635 ] && echo "File exist" || echo "File does not exist"
File exist

What I tried so far is

1) Copy log_path_only.txt to another place then execute : fail
2) By using cat command to copy contains to another file then execute: fail
3) I changed permission as "chmod +x log_path_only.txt" and try to execute: fail
4) I changed permission as "chmod 777 log_path_only.txt" and then try to execute: fail

5) I open log_path_only.txt by using nano, copy all lines, create a new file and paste everything inside and then execute new file: success

8
  • So all the /home/mywebsite/... files still exist after your attempt to run the file? If so, does log_path_only.txt have DOS line endings? Commented Oct 19, 2017 at 1:12
  • What shell are you using? Are you sure it's bash? I don't see a -e flag in the bash man pages. Commented Oct 19, 2017 at 1:26
  • chepner - yes file still exist after I attempt to run the file. I don't know what you mean by dos ending. there is rm -rf which supposed to run after I execute this command sh -e "log_path_only.txt" if I create log.txt and execute it is working but not for this file or anything copy from out of it. Commented Oct 19, 2017 at 1:55
  • igal - I am using bash yes. this is my dedicated server. I connect as root. Commented Oct 19, 2017 at 1:57
  • 2
    @igal: option -e is the same as set -e = exit on error. danone: if copy&paste fixed the problem then it's almost certainly 'DOS' (Windows) linebreaks. Windows uses CR and LF but Unix uses only LF and treats CR as part of your (file/dir?) name and that name doesn't exist; see stackoverflow.com/questions/2613800/… or stackoverflow.com/questions/82726/… Commented Oct 19, 2017 at 4:54

1 Answer 1

0

After you recommendations, I focused on CR and LF. I use this command to convert a file from dos to unix:

dos2unix log_path_only.txt

it is working now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.