CVS Checkout Cron Job - cron

I've been researching how to set up a cron job to checkout using cvs with pwd. I don't seem to find the way to do it. The commands I need to run is:
1) cd /listings/2016
2) cvs -d :ext:user#server.com:/usr/local/cvsroot checkout mydir
3) Now I will be prompted for password by the remote server, so I type it and hit enter, then the checkout is performed.
I have tried to login using
cvs -d :pserver:user#server.com:/usr/local/cvsroot/mydir login
So that the password get stored in passwd file, but this option seems to be disabled in the remote server.
I would really like to have all this in a cron job.
Any suggestions. Thanks,
-- Ty

Related

Automatic Synchronization with rsync

I am developing a script that will automatically keep a folder on two workstations synchronized using rsync. So far, I have gotten everything to work but I have one small thing I haven't figured out. Once, the rsync command is executed, it prompts for the password of the other workstation. However, I haven't been able to find a way to automatically enter that password once prompted in the terminal. I tried using the expect command, but that didn't work as the command didn't execute until after I enter the password.
Is there a solution to this?
Here is my script. I have two instances of the same VM, hence the same usernames
#!/bin/bash
LOCAL="/home/rams/Documents/"
RSYNC_OPTIONS="-avh --progress /home/rams/Documents/ rams#192.168.1.39:/home/rams/Downloads/"
PASSWORD="rams2020"
while true
do
inotifywait -e modify $LOCAL
rsync $RSYNC_OPTIONS
done
Solution shown here:
https://stackoverflow.com/a/3299970/8860865
TL;DR - Use an SSH keygen to generate a keyfile that will authenticate upon using the rsync command and the password is prompted. https://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/

Git commands in cron job

I am new to cron jobs. I want to run git commands through cron job.
I just tried a simple one with 'git status'.
I created a script
#!/bin/bash
echo git status
It is working when I run the script directly in the git view but not working in crontab.
I created the crontab as
* * * * * /path/to/script >> path/to/outputfile.
Please help me.
EDITED:
Please provide any sample program for running simple git commands in cronjob.
First off, you don't need an
echo `git status`
to output text, if you call the script with the >>. That way, you just echo the output you'd get anyway.
Concerning your problem, as was already discussed, you can give the direct path to git (such as /usr/local/bin/git). Furthermore, the script probably won't be called in the directory where your git repo lies; you have to cd there first, e.g.
#!/bin/bash
cd <wherever your repo lies>
/usr/local/bin/git status
and then add that script in your crontab as you already did. Hope that helps.

Creating a text file via SSH shell

I am trying to create a BASH shell script that runs through SSH on my shared hosting account to automate the git website control system detailed in:
http://danielmiessler.com/study/git/#website.
So far my bash script is right out of the above article:
cd ~/mydomains; mkdir $name.git;
cd ~/mydomains/$name.git; git init --bare;
/bin/vi ~/domains/$name.git/hooks/post-update
The first 2 lines work as expected.
when I add the third line the script seems to freeze up. the path to vi is /bin/vi in my environment.
Directly from the article I want the to perform the following:
vi /path/website.git/hooks/post-update
then insert:
GIT_WORK_TREE=/path/htdocs git checkout -f
Then close the file.
Could anyone offer me some advice on what to do now?
Why are you try to use vi in script just to add line into file?
Problem is that vi is interactive, but you're looking how to automate this ;-)
You should use
echo "GIT_WORK_TREE=/path/htdocs git checkout -f" >> ~/domains/$name.git/hooks/post-update
I believe you need to make the hook script executable before git will use it.
chmod +x /path/website.git/hooks/post-update
After that, after pushing, the script ought to be executed.

Run script on two machines

I have a shell script that I need to automate with cron. At our office, there is a specific machine that I must log in to in order to use cron. My problem is, that the script I have written interacts with git, using git commands to pull code and switch branches. The machine where I am able to schedule cron jobs and the script is being run from does not have git on it. I have a separate machine that I log in to when I am using git. Is there an easy way for me to run my script from the cron system and run the git part from the git system?
UPDATE: I am still interested if this can be done, but my team has acquired a new machine that we will set up however we choose, meaning that it will have cron and git. Thanks for any ideas
As some people have mentioned above, ssh is the way to do this. This is a bash line that I use a lot in my job, for gathering data from other servers:
ssh -T $server -l username "/export/home/path/to/script.sh $1 $2" 1>traf1.txt 2>/dev/null
The above code sample will connect to the ip $server, as user username and run the script script.sh, passing it the parameters $1 and $2. Instead of redirection you could also assign the command output to a variable, just as you would with any other command in your script.
PS: Please note that in order for the above to work, you will need to set up passwordless login between those machines. Otherwise your script will break to request password input, which is most probably not the desired behavior.

linux script to automate ftp operation

I need to transfer a file from my linux server to a FTP server.
My shell script is :
#! /bin/ksh
HOST='my_ip'
USER='userid'
PASSWD='password'
FILE='file.txt'
DIREC='/eir_log'
ftp -in $HOST << EOMYF
user $USER $PASSWD
binary
mkdir $DIREC
cd $DIREC
pwd
quit
EOMYF
pretty simple code. but the problem is though I am logging in the FTP server fine, but its not allowing me to create a new directory in the FTP server. At first i thought some error with my script, but even individually if i run a mkdir in the ftp server its showing create directory failed.
Can somebody let me know the possible error, or if any eror in my code that i am missing out on.The pwd is working fine though, which means there is no problem loging in the ftp site through script.
Thanks in advance for your help
Have a look at expect
Something to get you started
#!/usr/bin/expect
set timeout 120
spawn ftp 192.168.0.210
expect "Name"
send "root\r"
expect "Password:"
send "pass\r"
expect "ftp> "
send "bye\r"
Probably lftp ( ftp scripting client ) will be something you need ( look among your distro's packages ). Error creating directories is probably related to permissions of the dir inside which you try to create it.
http://lftp.yar.ru/desc.html
Have you tried using SCP (Secure Copy)?
scp -r /dir/to/"file.txt" username#hostname
*if you're in the directory of the file/folder you wish to send then you don't need to define the complete filepath
Have a look at this article if you want to scp without having to enter your password. http://www.thegeekstuff.com/2008/06/perform-ssh-and-scp-without-entering-password-on-openssh/
If you are root or have admin privileges then you shouldn't need to sudo your way into making a directory. It will be best to run remote commands without sudo just in case a malicious code piggybacks your script

Resources