Am writing a script that does a rm/mv if a file exist, however, in one scenario, one of the variables which is supposed to a variable for a directory is undefined/blank so instead of the variable resolving to /tmp/logfile.dmp, it resolves instead to / so the rm translates to a rm / instead of rm /tmp/logfile.dmp.
Luckily I guess, the rm fails because / is a directory. In the same instance, a similar thing happen to one of the mv command, i.e. it translates to mv /, and luckily the mv gives Device or resource busy.
To avoid really causing a problem, I temporarily disabled all rm and mv in my script.
Can anyone please advise if there is a safe way to run a rm or mv to avoid removing /mv'ing the wrong file or there is no such way or doing so and I will just have to make sure that whatever I am trying to remove or mv resolves to the right file that I want to remove?
If you know you are deleting files, you can check if it a file and then delete. Something like this
May be you should hard code a check for "/".
Another option is use to check the emptiness of the variable before using it
Say, $var is supposed to have the file name, tmp.log but it was not there, so you can check the variable using
Hey Guys,
I'm swamped writing code for the forums:
Could someone write a script or command line to safely delete files with special chars in filenames from a directory:
Example:
-rw-r--r-- 1 root root 148 Apr 30 23:00 ?xA??
-rw-r--r-- 1 root root 148... (8 Replies)
Given a directory containing say a few thousand files,
please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents.
func(a_directory_name) output -> {“matches”: , ... ]}
e.g. func(“/home/my/files”) where the directory... (7 Replies)
I wanted to know whether all files under /tmp can be safely removed. I guess that /tmp may also have temporary files for applications currently being worked on, so at the most those applications may just shut down.
I hope that my question is clear whether all files under /tmp can be safely... (5 Replies)
I am using:
reboot -- cdrom
However I'm afraid of causing file system errors/corruption. I've seen many threads say that
init 6
is safer, but I need to get to CDROM.
Is there a command that is as safe as init, but can boot to cdrom, or should I not worry so much about the reboot... (5 Replies)
I have a string like root=/dev/sda3 noacpi foo "Baz mumble" which I would like to separate into tokens like a shell does. This would be easily done with eval but that would open a security hole big enough to drop a cow through, injecting arbitrary code would be easy as pie. How can I parse this... (15 Replies)
Greetings,
I need some help performing a system admin function that I have been tasked with. The request seems simple enough, but my feeling is that it might be more complicated than it seems.
Here is what i've been tasked with:
SunOS 5.10 Generic_142900-15 sun4u sparc SUNW,SPARC-Enterprise... (3 Replies)
Hello everyone. Need some help copying a filesystem. The situation is this: I have an oracle DB mounted on /u01 and need to copy it to /u02. /u01 is 500 Gb and /u02 is 300 Gb. The size used on /u01 is 187 Gb. This is running on solaris 9 and both filesystems are UFS.
I have tried to do it using:... (14 Replies)
Sceduled backups with vdump have been delayed as a mounted system had crashed while I was away for 2 weeks. Now there are 5 simultaneous vdumps running very slowly. The full system backup usually takes a whole weekend.
Can I safely kill these? (I will have to live without a backup untill next... (4 Replies)