I am using LFTP for file transfer. The file transfer is successful but at the end of a successful file transfer, only the number of bytes transferred is displayed. I need to know the time taken in transferring the file, as well.
I am using LFTP because I need to provide the username, password and the required ftp command all in a single command. (lftp -u username,password -e "your command;quit" ftp.site.com). Therefore, using some other FTP daemon is probably not an option.
Is it possible to display transfer time using LFTP?
Thanks
Use the time command. Use it before most any command and it will give you a run down of the time it takes to complete that command.
time lftp -u username,password -e "your command;quit" ftp.site.com
Output will be like this:
real 0m2.963s
user 0m0.000s
sys 0m0.012s
Related
We have a script I use at work, that I did not write, that when its doing it thing prompts for same password about 5-6 times. I'd like to write something into it that when it asks for the password the first time, it stores the pw and autocompletes it each time thereafter. Is it possible to do this is a bash script? My understanding us the script is doing an ssh to another server and running an update on a file to make sure it has the most current version and if you are entering more than one user into the file it need to ask every time it updates.
First off, remember this is TERRIBLE SECURITY PRACTICE!!! With that in mind, what is the reason for the password prompt? When using sudo, you can always do this:
#!/bin/bash
read -s PASSWORD
echo $PASSWORD | sudo -S <whatever you want to do that prompts for password>
Explanation:
sudo -S reads password from stdin
Source: https://superuser.com/questions/67765/sudo-with-password-in-one-command-line
So in conclusion, you can use sudo along with password from stdin to whatever you want to do.
I hope this helps!
I am intending to send a huge file around 1+GB over to the remote side using SFTP. However, it seems to work fine in interactive mode(when I sftp#xx.xx.xx.xx and enter the password manually, then I key in the put command). But when I run it in shell, it always timeout.
I have set the client and server ClientAliveTimeout settings at /etc/ssh/sshd_config but it still occurs.
Below is the linux script code
sshpass -p "password" sftp user#xx.xx.xx.xx << END
put <local file path> <remote file path>
exit
END
The transfer of files takes 10 min when using interactive mode
when run using script, the file was incomplete based on filesize.
Update: Current transfer during interactive mode shows the small files went through but the big file was stalled halfway during transfer.
I prefere lftp for such things
lftp -u user,passwd domain.tld -e "put /path/file; quit"
lftp can handle sftp too
open sftp://username:password#server.address.com
I am building a bash script for my work to make initial setup and windows-domain join for our Ubuntu machines easy enough for someone who knows nothing about Linux can do it. I have found a lot of people that say that you shouldn't pass passwords through a script but to be efficient, I have to. The script prompts for info and credentials in the beginning and it needs to be able to be left to do it's job without interaction. I can't have it visible through ps when I pass it and I can't have it stored as an unsecured variable. Any suggestions?
If you really must do this, you can read the credentials into variables with read -s early in the script and then pass those values to the prompts. For example:
read -p "Enter your username: " username
read -sp "Enter your password: " password
echo
I included the blank echo because the -s option for read prevents the user's typing from appearing in the terminal, including the new line usually created after a user presses Enter when answering a prompt.
You can then use the $username and $password variables for the rest of your script and the credentials will not have to be stored outside of memory, meaning they will be lost/destroyed after the script completes.
However, note that any programs or utilities which take the credentials as command-line arguments will display those to other users on the machine running the script. For example, if I were to run a MySQL query using this method, I could do:
mysql -u "${username}" -p"${password}" -e "SHOW DATABASES;"
Other users on the machine could see the credentials while that was running with something like ps:
ps -ef | grep mysql
...
watrudoin 29512 29443 0 12:57 pts/4 00:00:00 mysql -u MyUserName -phunter2 -e SHOW DATABASES
You just need to be aware that what you are doing is not necessarily secure, but it seems that you already are.
I am writing a script which will automatically capture a screenshot and trigger iSight to take a still photo when the script is run, then upload it to FTP. Everything is perfect other then one thing, my FTP requires a username and password to be entered when prompted (after both images are captured)
heres what I have:
echo “GOLDENEYE ACTIVATED….”
screencapture -x screen.jpg
imagesnap Mugshot.jpg
ftp <YourServerHere>
Terminal Responds:
Connected to <YourServerHere>
Now, Username must be entered when this appears:
220 Welcome to <ServerDomain>, FTP server standing by ...
Name (<ServerName>.<DomainName>.:<Name>): <Type UserName Here - Hit Enter>
And, Password will be entered upon successful entry of a valid Username:
331 Hello <UserName>, your FTP account password is required:
Password: <Type Your Password Here - Hit Enter>
After the proper credentials are entered, Terminal will respond:
230-Login successful, your current directory is /
230 0 Kbytes used (0%) - authorized: 7340032 Kb
Remote system type is UNIX.
Using binary mode to transfer files.
And, to upload the images:
ftp> put /Mugshot.jpeg
ftp> put /Screen.jpeg
I am attempting to Automate the username and password entry after the prompts are given, in order for the script to be successful
the text would be, "username" and "password" to be entered after the each prompt is given.
i am completely new to terminal and scripts, just playing around in my spare time, please excuse anything which is incorrect here, thanks for ANY help and education!
A general solution is the expect command.
But for your task, it's an overkill.
The ftp reads commands from a standard input.
So just do:
ftp -n < command.txt
The -n prevents the automatic prompts for username/password. We provide these explicitly using the user command below.
The commands.txt file will look like:
open host
user user password
put /path
bye
I'm using plink to run a script on a remote server (Linux) from a Windows machine. Part of the script prompts for inputs (authentication to various other remote servers that use different credentials). I don't want to store the password in the script as each use will be using their own for auditing reasons.
I need the prompt to be transmitted to the Windows terminal window and I need the input transmitted back to the Linux box. Additionally I need to write log all this into a file, like this:
plink username#unixbox /etc/scrips/myscript.bash > report.txt
At the moment the above works but all that prints to report.txt is the prompts
please enter password for reportBox1?
please enter password for reportBox2?
Instead I need it to send the password prompt and input to the Linux box to continue running the script as it normally would, only remotely. So the output of report.txt would read:
please enter password for reportBox1? *
File 1
File 2
File 3
please enter password for reportBox2? *
Data a
data b
data b
Hope that makes sense. If there's something better than plink can be used such as putty's ssh.exe please let me know that one instead.
First off: plink is PuTTY's ssh.exe.
If you want to be able to answer the password prompt on the Windows machine, you need to tell plink to allocate a pseudo-terminal with -t:
plink -t username#unixbox /etc/scrips/myscript.bash
Now you get the prompt and input will be sent back. But if you redirect STDOUT to report.txt...
plink -t username#unixbox /etc/scrips/myscript.bash > report.txt
...you won't see the prompt, because it's redirected into report.txt (although the script still runs and waits for your input). To get around this, you need some tool which allows you to redirect the output to multiple destinations - STDOUT and report.txt at the same time. In the *nix world, the command for this is tee. There are ports of tee for Windows:
as part of GnuWin32 (this is what I'm using)
as part of UnxUtils
as batch, perl and rexx versions
Having set one of those up, you'd do:
plink -t username#unixbox /etc/scrips/myscript.bash | tee report.txt
Security note: If the password prompts in the script on the Linux machine echo what was input, the passwords will of course also be logged in report.txt, which might be a problem.