Moving a file with rsync works at the command line, but not in cron - rsync

I'm working on a home automation system using a Raspberry Pi. As part of this, I'd like the rPi to pull a file from my web server once a minute. I've been using rsync, but I've run into an error I can't figure out.
This command works fine when run at the command line on my rPi:
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress username#example.com:/home/user/example.com/cmd.txt /home/pi/sprinkler/input/cmd.txt
...but when it runs in cron, it produces this error in my log:
Unexpected local arg: /home/pi/sprinkler/input/
If arg is a remote file/dir, prefix it with a colon (:).
rsync error: syntax or usage error (code 1) at main.c(1375) [Receiver=3.1.2]
...and I just answered my own question. Extensive googling around didn't turn up an answer but I just tried putting my rsync command into a bash script, and running the script in cron instead of the command and now everything works!
I'll put this here in case anyone else stumbles over this issue. Here's a script I called "sync.sh"
#!/bin/bash
# attempting a bash shell to use rsync to grab our file
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
--progress user#example.com:/home/user/example.com/vinhus/tovinhus
/cmd.txt /home/pi/sprinkler/input/

Related

Rsyncing both ways while handling deletes

Right now, I am currently running rsync in two different ways:
rsync -r -avz --delete --progress -e "ssh -p 8443" root#<my_server>:~/app ~/Desktop/;
rsync -r -avz --progress -e "ssh -p 8443" ~/Desktop/app root#<my_server>:~/app/
Obviously the problem here is that if a file doesn't exist on the server, then it gets deleted locally. So if you created a file locally after it synchronized to the server, the first command will run and delete it again locally. If you switch the --delete option to the other command, then the reverse happens.
I've tried experimenting and researching this to do it a few different ways, but I cannot seem to come around to a way that synchronizes changes on both sides depending on what happened first.
An alternative that I saw was Unison, but I have errors with this as well when the version doesn't match between the client and the server.

Start tcsh in a specific directory

Does tcsh support launching itself in a remote directory via an argument?
The setup I am dealing with does not allow me to chdir to the remote directory before invoking tcsh, and I'd like to avoid having to create a .sh file for this workflow.
Here are the available arguments I see for v6.19:
> tcsh --help
tcsh 6.19.00 (Astron) 2015-05-21 (x86_64-unknown-Linux) options wide,nls,dl,al,kan,rh,color,filec
-b file batch mode, read and execute commands from 'file'
-c command run 'command' from next argument
-d load directory stack from '~/.cshdirs'
-Dname[=value] define environment variable `name' to `value' (DomainOS only)
-e exit on any error
-f start faster by ignoring the start-up file
-F use fork() instead of vfork() when spawning (ConvexOS only)
-i interactive, even when input is not from a terminal
-l act as a login shell, must be the only option specified
-m load the start-up file, whether or not owned by effective user
-n file no execute mode, just check syntax of the following `file'
-q accept SIGQUIT for running under a debugger
-s read commands from standard input
-t read one line from standard input
-v echo commands after history substitution
-V like -v but including commands read from the start-up file
-x echo commands immediately before execution
-X like -x but including commands read from the start-up file
--help print this message and exit
--version print the version shell variable and exit
This works, but is suboptimal because it launches two instances of tcsh:
tcsh -c 'cd /tmp && tcsh'

incron and rsync not working

I have incron setup and working, i can see things being logged when files are changed.
I've tried my rsync command separately and that works fine. But when rsync in triggered by incron, nothing happens. i explicitly stated all the paths i could see.
here is my incrontab -e
/home/dir/dir/ IN_MODIFY sudo rsync -pogr -e 'ssh -i /root/.ssh/rsasync1' /home/dir/dir/* root#ipaddress:/home/dir/dir/
i'm working as root right now and executing the command as root. also tried /usr/bin/rsync and that didn't work in addition to sudo rsync etc...
thanks!
Try this in incrontab:
/home/dir/dir/ IN_MODIFY sudo rsync -pogr -e ssh -i /root/.ssh/rsasync1 /home/dir/dir/* root#ipaddress:/home/dir/dir/
In above command I have removed the quotes. Incrontab can not run with Single quote OR double quote.
Remember: Pleas keep the quote while executing in terminal.

urxvt -cd "/abs/path" not loading user zsh config

When I run urxvt -cd "/absolute/path" to start a terminal in a directory, it doesn't load my user zsh settings, it only loads the global ones in /etc.
Here's some context: Running latest stable versions of rxvt-unicode and zsh (on Arch Linux). I've got ZDOTDIR=~/.zsh in case that makes a difference (but I doubt it, since I tried symlinking ~/.zshrc to ~/.zsh/.zshrc.) If I just run urxvt then it works fine, but it's with the -cd flag that it messes up.
The reason I'm trying to do this is to start a terminal in the current location from Thunar AND have it read my user zsh configuration file. So if you know another way of doing this then that will work too.
Try adding -ls to its options to run it as login shell, like:
urxvt -ls -cd "/absolute/path"
Otherwise it will spawn a subshell. If that doesn't work for you, it still possible to use:
urxvt -e /where/is/your/zsh -i -l -c "cd /where/you/want/it"
Or (regarding the Thunar custom action):
urxvt -cd %f -e /where/is/your/zsh -i -l

Get current progress of rsync daemon

I am running rsync process as a daemon. Rsync tool does not accept --progress and --daemon options together. I thought to parse the /var/log/messages and rsyncd.log file, is it a correct approach ? Is there any other possibility to get the current progress of the synced data ?
Current usage of rsync -
rsync --daemon --config="/etc/rsyncd1.conf" --address=10.2.2.3
After adding --progress option
rsync -v --progress --daemon --config="/etc/rsyncd1.conf" --address=10.2.2.3
Starting rsync [10.2.2.3]: rsync: --progress: unknown option (in daemon mode)
(Type "rsync --daemon --help" for assistance with daemon mode.)
rsync error: syntax or usage error (code 1) at options.c(1005) [client=3.0.6]
[FAILED]
What about following workaround?
I've made a script, that calculates the whole rsync progress in Python. You could modify it to send needed info to syslog or whatever suits your needs and run it as daemon.

Resources