LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-23-2017, 01:14 PM   #1
powderburns
LQ Newbie
 
Registered: Dec 2011
Distribution: debian, mint, opensuse, fedora, ubuntu, fbsd
Posts: 11

Rep: Reputation: Disabled
Is there a cli method of running a command twice without having to type it twice?


I'm doing some backups with rsync over wifi and I am dealing with broken pipes by running my command multiple times, but typing out the command twice separated by a ; or && is tedious without being able to copy & paste the command. Is there a trick to tell my shell to run the command n times instead of writing out
Code:
rsync arguments source destination ; rsync arguments source destination
?

eta: I also just realized this would prompt me for a password each time rsync is run, any way around that?

Last edited by powderburns; 03-23-2017 at 01:20 PM. Reason: appended
 
Old 03-23-2017, 01:21 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,607
Blog Entries: 3

Rep: Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851
Depends on the shell. In many you can just press the up arrow. Also in many you can press !! and it will repeat the last one again.

Code:
date;
!!

date; !!
If you are searching through your command history, ctrl-R will search backwards for you.
 
1 members found this post helpful.
Old 03-23-2017, 01:34 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,607
Blog Entries: 3

Rep: Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851
Or you can run rsync in a loop until it succeeds.

Code:
while ! rsync -options source/ destination/; do true; done;
That way it will keep trying until the transfer is completed successfully.
 
2 members found this post helpful.
Old 03-24-2017, 09:02 AM   #4
powderburns
LQ Newbie
 
Registered: Dec 2011
Distribution: debian, mint, opensuse, fedora, ubuntu, fbsd
Posts: 11

Original Poster
Rep: Reputation: Disabled
Both suggestions worked great. I finished my remaining transfers without having to supervise the shell all night. Thanks for your help!
 
Old 03-24-2017, 09:55 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,607
Blog Entries: 3

Rep: Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851
No worries. It's a trick that also works with ssh if you use that as well. It needs tmux or screen over on the server and key-based authentication is prerequisite.

Code:
ssh-add ~/.ssh/server_key_ed25519

while ! ssh -t -i ~/.ssh/server_key_ed25519 server.example.com 'tmux a || tmux'; do sleep 1; done;
Useful when traveling or in other situations where connectivity is irregular.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI to know the type of partition of a harddisk? Xeratul Linux - General 4 05-18-2012 01:11 PM
Javascript: Adding method to Array type hydraMax Programming 2 10-04-2011 12:43 PM
LXer: Mass-Rename Files Using an Easy CLI Method LXer Syndicated Linux News 0 07-07-2008 06:20 PM
CLI tool to determine processor type? wanderingmind Linux - Software 3 09-11-2007 06:47 PM
Help, no CLI at boot! Just a black screen, can still type though, just can't see text Slovak Slackware 12 11-17-2004 06:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration