I am using a script on RHEL server where I'm copying a backup of the /etc/syslog.conf file before making configurable changes in it. I used the below command in the script:
cp -pr /etc/syslog.conf /etc/syslog.conf.bkp.`date +"%d%m%Y"`
The script ran absolutely fine on one RHEL server, but on the other it shows the below error:
cp: cannot stat `/etc/syslog.conf': No such file or directory
I also checked the /etc/syslog/conf file exists in the server just fine.
Why is the difference of behaviour. How to resolve it ?
cp: cannot stat is mainly because cp command can't see the file. It can be for two reasons.
File is not present
You don't have permission to view the file.
If you check these two things you should be able to find the answer
Related
I have to mount five of my main directories viz. (/home, /usr, /tmp, /root and /var) for a specific project. I did some googling and found out a set of commands which can be executed to mount a particular directory. The commands were as follows:
#dd if=/dev/zero of=/filesystems/tmp_fs seek=512 count=80000000 bs=1M
#mkfs.ext3 /filesystems/tmp_fs
After mounting, the entry was registered in fstab as below,
/filesystems/tmp_fs /tmp ext3 noexec,nosuid,loop 1 1
And at the last step, the directory was mounted.
I followed the same procedure for mounting all the directories specified above. In the end, I could only mount "/root" and "/tmp" directories without any errors. Rest all the three directories gave some or the other error. After mounting '/home' directory, I am getting the following error "No directory. logging in with HOME=/" and similarly after mounting '/var'
directory I got the following error "/var/lib/apt//lists No such file
or directories". Mounting of '/usr' directory caused the OS to crash as
a result of which we could not even login as root user and also some
basic commands like 'vi' and 'sudo su', to name a few were not found in
the system. ecause of these issues, the only option left was to format
the OS since we could not even revert this step because of the missing
commands.
Any help or suggestion here in the right direction would be of great help here.
Thanks for the consideration.
I am hoping that a more experienced set of eyes will find something obvious that I am missing or will be able to help me work around the errors that mv and rsync are producing. Up for the challenge?
Basic idea:
I have a bash script in which I am automating the move of files from one directory to another.
The problem:
When I run the script, periodically I get the following error from the mv command:
mv: cannot stat `/shares/directory with spaces/test file.txt': No such file or directory. The error code from the vm command is 1. Even more odd, the file move actually succeeds sometimes.
In addition, I have a branch of logic in the script that will alternately use rsync to move/copy specific files (from the same local file system source and destination as the mv command mentioned above). I get a similar error related to the stat() system call:
rsync: link_stat "/shares/directory with spaces/test file.txt" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
This error does not always manifest itself when the script is run. Sometimes it completes the file move without complaint, while other times it will return the error consistently when the script is run successive times.
There is one additional ingredient you should be aware of (and I am growing to suspect this as a key ingredient in my grief): the directory /shares/ is a directory that is being monitored by an installation of Dropbox -- meaning it is watched and mirrored by an installation of Dropbox. At this point, I am unable to determine if dropboxd is somehow locking the file, or the like, such that it cannot be stat-ed. To be clear, the files are eventually freed from this state without further intervention and are mv-able.
The code:
mv -v --no-clobber "${SOURCEPATH}${item}" "${DESTINATIONPATH}${item}"
More info:
The following might, or might not, be relevant:
mount indicates the filesystem is ext4
Presumably, ownership and permissions shouldn't be an issue as the script is being run by root. Especially if the file system is not fuse-based.
The base "directory" in the path (e.g. /shares/) is a symlink to another directory on the same file system.
The flavor of Linux is Debian.
Troubleshooting:
In trying to eliminate any issues with the variable expansion or their contents, I tried hardwiring the bash script like such:
mv -v --no-clobber "/shares/directory with spaces/test file.txt" "/new destination/directory with spaces/test file.txt" after verifying via ls -al that "test file.txt" existed. For reference the permissions were: -rw-r--r--
Unfortunately, this too results in the same error.
Other possible issues I could think of and what I have done to try to rule them out:
>> possible issue: slow HDD (or drive is in low power mode) or external USB drive
>> findings: The drives are all local SATA disks set to not park heads. In addition, even when forcing a consistent read from the file system, the same error happens
>> possible issue: non-Linux, NFS or fuse-based file system
>> findings: nope, source and destination are on the same local file system and mount indicates the file system is ext4
>> possible issue: white space or other unprintable chars in the file path
>> findings: verified that the source and destination paths where properly wrapped in quotes
>> possible issue: continuation issues after escaped newline (space after \ in wrapped command)
>> findings: made sure the command was all on one line, still the same error
>> possible issue: globbing (use of * in specifying the files to move)
>> findings: nope, each file is specified directly by path and name
>> possible issue: path confusion from the use of local path
>> findings: nope, file paths are fully qualified starting from /
>> possible issue: the files are not actually in the path specified
>> findings: nope, verified the file existed right prior to executing the script via ls -al
>> possible issue: somehow the --no-clobber of mv was causing issues
>> findings: nope, tried it without, same error
>> possible issue: only files created via Dropbox sync to the file system are problematic
>> findings: nope, created a local file directly via touch new-local-file.txt and it too produced the same stat() error
My analysis:
The fact that mv and rsync produce similar stat() errors leads me to believe:
there is some systemic underlying boundary case (e.g. file permissions/ownership or file busy) that is not accounted for in the bash script; or
the same bug is plaguing me in both the mv and the rsync scenarios.
Desired outcomes:
1. The root cause of the intermittent errors can be identified.
2. The root cause can be resolved or worked around.
3. The bash script can be improved to gracefully handle when the error occurs.
So, with a lot more troubleshooting I found an errant rsync statement some 200 lines earlier in the script that was conditionally executed (thus the seeming inconsistent behavior). That rsync --archive ... statement was being passed /shares/ as its source directory, therefore it effected the /shares/directory with spaces/ subdirectory. That subdirectory was the ${SOURCEPATH} of the troubling mv command mentioned in my post above.
Ultimately, it was a missing --dry-run flag on the rsync --archive ... statement that causing the trampling of the files that the script later expected to pass to mv to process.
Thanks for all who took the time to read my post. Though I am bummed to have spent my and your time on what turned out to be a bug in my script, it is reassuring to know that:
- computers are not irrational
- I am not insane
- there is not some nefarious, deep rooted bug in the linux file system
For those that stumble upon this post in the future because you are experiencing an error of cannot stat, please read my troubleshooting notes above. Much research went into that list. One of those might be your issue. If not, keep debugging, there is an explanation. Good luck!
I would like to chroot my ssh connexion on my debian 8 server but I ahve a problem.
I found this tutorial https://www.howtoforge.com/chrooted-ssh-sftp-tutorial-debian-lenny but I have an error.
I sue this script:
http://www.fuschlberger.net/programs/ssh-scp-sftp-chroot-jail/make_chroot_jail.sh
he say:
usermod: user johnde is currently used by process 21730
Adding User rdata to jail
Copying necessary library-files to jail (may take some time)
cp: cannot stat '/lib/libnss_compat.so.2': No such file or directory
cp: cannot stat '/lib/libnsl.so.1': No such file or directory
cp: cannot stat '/lib/libnss_files.so.2': No such file or directory
cp: cannot stat '/lib/libcap.so.1': No such file or directory
cp: cannot stat '/lib/libnss_dns.so.2': No such file or directory
Copying files from /etc/pam.d/ to jail
Copying PAM-Modules to jail
cp: cannot stat '/lib/security': No such file or directory
Did i make something wrong ?
thanks.
The library file locations changed between Lenny (actually Squeeze) and Jessie. Compare the path to libnss_compat.so.2 in squeeze to the one in jessie and adapt the code accordingly.
Hard-coding paths in the script seems less than ideal, anyway; perhaps, the part of the code which figures out where to find libraries (the part with ldd) should perhaps remember where it found them, and attempt to copy the remaining libraries from the same location(s).
Here is a patch file to fix make_chroot_jail.sh so it works with Debian 8.2 (aka Jessie) 32-bit. In theory it should work with the amd64 version too as I looked up the new lib folder names for it too. But I have not tested that.
http://www.jonmccain.net/downloads/make_chroot_jail_jessie.patch
use the command:
patch -i make_chroot_jail_jessie.patch -o make_chroot_jail_jessie.sh
to get the new script.
I tried with copying directory and files to remote Linux machine using rsync and incrontab.
It's working fine copying files to remote server.
Incrontab
/data/AMOS_SHARE/CHV_BE/ IN_MODIFY,IN_CREATE,IN_DELETE,IN_CLOSE_WRITE,IN_MOVE /data/AMOS/jboss/chv_rsync.sh
Rsync
#!/bin/bash
chmod -R 775 /data/AMOS_SHARE/CHV_BE
rsync -avuzh /data/AMOS_SHARE/CHV_BE/ jboss#xx.xx.xx.xx:/data/AMOS_SHARE/CHV_BE/
I created some files in /data/AMOS_SHARE/CHV_BE/ folder. It worked fine as well as I created folder in that, it is also working fine. But whenever I creat files in a sub folder, it's not working.
Please help me out.
In incrond recursively monitoring is not implemented yet, so the events in sub-directories are not monitored. You can do it by adding a additional watchers to sub-dirs but I would recommended to use
another tool:
Watcher
Also you can try ionotifywait tool (example)
inotifywait /tmp/test_dir -m -r
and parse the output of this command.
I've got a virtual dedicated server (running FreeBSD 6.x) and I need to regulary backup files from one folder to another, say from /home/LOGIN/data/www/mydomain.com/test1 to /home/LOGIN/data/www/mydomain.com/test2. I've tried different approaches:
rsync -a /home/LOGIN/data/www/mydomain.com/test1 /home/LOGIN/data/www/mydomain.com/test2
cp /home/LOGIN/data/www/mydomain.com/test1 /home/LOGIN/data/www/mydomain.com/test2
cp www/mydomain.com/test1 /www/mydomain.com/test2
but all this didn't work, it gave error #127 and others.
AFAIK this can be done using a php script to run by cron also.
what is the better way?
try
cp /home/LOGIN/data/www/mydomain.com/test1/*
/home/LOGON/data/www/mydomain.com/test2
and make sure the test2 directory is existent