I'm trying to use FTP on shell script to put a file from one server to other one. Following the code
HOST='206.35.8.213'
USER='my_username'
PASSWD='_mypassword'
FILE='mydata.log'
PATH='/export/home/oracle/europa/'
ftp -inv $HOST << EOF
user $USER $PASSWD
cd $PATH
put $FILE
bye
EOF
this is throwing the error as follows
./ftp.sh: line 9: ftp: command not found
Here the FTP available on the server. Could any one help on identifying the issue.
You've over written the PATH variable which is used to search for binaries. What you've effectively told the shell is that the ftp binary will be in /export/home/oracle/europa/. Change your variable name to something else.
As a rule, bash uses upper case for it's variables, see Shell Variables in the bash manpage. I'd recommend using a different naming convention for your own variables. If you had named PATH, path exportDir or similar you wouldn't have had any problems.
The package for FTP server is vsftpd , but for ftp client it is ftp .
You need to install ftp service to start ftp sessions.
Related
I am trying to setup svn over ssh on an OS X server. In order to do so, I read that I need a wrapper to set umask and - in my case - to set the repository root. A quick and dirty way to do that is to rename /usr/bin/svnserve and place a wrapper script at that location. However SIP protects that location from any changes, and I would prefer a cleaner solution anyway.
So I created a wrapper script at /usr/local/bin/svnserve and created /etc/ssh/sshrc with
PATH=/usr/local/bin:$PATH
I have verified that this file gets executed when initiating a remote ssh command from my client by writing to a log file. However, the modified PATH does not seem to get passed to the command environment:
ssh hostname 'echo $PATH'
Password:
/usr/bin:/bin:/usr/sbin:/sbin
Am I overlooking something? Or is /etc/ssh/sshrc the wrong place to set a path? If so, what's the right place?
Other places I've tried: /etc/profile and /etc/bashrc, but none of these seem to get executed in connection with an ssh command.
Note: It is not an option to change the client behavior (like, for example, adding the desired path to the command).
/etc/sshrc does not run in the same shell instance with the remotely-issued command, so the PATH update does not persist through.
Some of the available options:
You can set AcceptEnv PATH on the server to configure it to accept a PATH sent by the remote system, and SendEnv PATH on the client (in ~/.ssh/config, or as an argument to ssh passed with -o, or in /etc/ssh/ssh_config).
In /etc/ssh/sshd_config on the server, you can set the option PermitUserEnvironment to yes; with that done, the variable and value can be added to ~/.ssh/environment in the individual user's account on the server.
You can use ForceCommand to override the remotely requested command, either with something like /usr/bin/env PATH=/usr/local/bin:/usr/bin:/bin svnserve or simply /usr/local/bin/svnserve
I'm somewhat new in Linux. I have to read logs on a remote host and save certain lines, found with grep command to a file. The problem is that I don't have permissions to create a file on the host. Is there a workaround the issue? Thanks!
You can run something like the following:
ssh remotehost "grep certainline logs*" > file
to save the file locally.
Otherwise, you might be able to create a file in /tmp.
You don't mention but I'm going to assume you're using ssh to access the remote machine. So you can run the command on the remote machine and redirect the output on the local machine like so:
ssh remotehost 'grep pattern /var/log/mylog' > mylocalfile
Note that the redirection occurs outside the quoted command that is given to ssh to send to the remote host. If you were to put it inside the quotes then the redirection would occur on the remote side.
I want to login to my FTP server using shell scripting. I made a .sh file having contents as
ftp
open 172.31.1.45
but it's not working. The second command is not executing. Please help. I am new to linux so please forgive if this is a stupid question
try this:
#!/bin/sh
HOST="yourhost"
USER="user"
PASSWD="pass"
FILE="file.txt"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
If it's just a matter of simple file transfers, you might want to look at using a tool like ncFTP, wget, or cURL, which can do file transfers in a single command. Using these tools, you can simply pass the username, password, host address, source file, and destination file in one command.
Hi I have been given a task of copying files from a given server to local machine. Even I can do it manually using the command line but I need to write a script to automate it. I dont have any clue how to do it using shell, how to give the password which we would have done manually. I went through other posts but did not get the precise answer.
Are there better ways than using SCP command?
Thanks in advance
The preferred + more secure way to do this is to set up ssh key pairs
That being said, if there's a specific need to supply passwords as part of your shell script, you can use pscp, which is part of putty-tools:
If you are on ubuntu, you can install it by:
sudo apt-get install putty-tools
(Or use equivalent package managers depending on your system)
Here's an example script of how to use pscp:
#!/bin/bash
password=hello_world
login=root
IP=127.0.0.1
src_dir=/var/log
src_file_name=abc.txt
dest_folder=/home/username/temp/
pscp -scp -pw $password $login#$IP:$src_dir/$src_file_name $dest_folder
This copies /var/log/abc.txt from the specified remote server to your local /home/username/temp/
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