-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

danone
  • 304
  • 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? – chepner Oct 19 '17 at 01:12
  • What shell are you using? Are you sure it's bash? I don't see a -e flag in the bash man pages. – igal Oct 19 '17 at 01: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. – danone Oct 19 '17 at 01:55
  • igal - I am using bash yes. this is my dedicated server. I connect as root. – danone Oct 19 '17 at 01:57
  • I don't know specifically why it isn't working, but I would modify your text file (really, this is UNIX/Linux, we don't need dot-extensions on files per se, and using .txt on what is a basic script is kind of awkward) so that it conforms with a more standard shell script format. For example, first line should probably be a shebang #!/bin/bash. Yes, not all of these things are always necessary, but when you throw a bunch of commands in a text file and it doesn't execute as a script, the first troubleshooting step is to make it more like a real script. – 0xSheepdog Oct 19 '17 at 03:53
  • 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 https://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix- or https://stackoverflow.com/questions/82726/convert-dos-line-endings-to-linux- – dave_thompson_085 Oct 19 '17 at 04:54
  • 0xSheepdog and dave_thompson_085, I know we don't need extension It just needs to be with extension because of program generating that way and developer choose .txt . It doesn't matter even .txt can be executed by sh. I also attached nano screenshot if you can have a look it? I don't see any dos windows line breaks how can I find these breaks ? – danone Oct 19 '17 at 06:31
  • Related: https://unix.stackexchange.com/questions/88811/remove-m-character-from-log-files – Kusalananda Oct 19 '17 at 06:45

1 Answers1

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
danone
  • 304