LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2022, 11:39 AM   #1
jefferj54
LQ Newbie
 
Registered: Aug 2013
Posts: 5

Rep: Reputation: Disabled
I need advice for a basic SSH Ubuntu loop script..


..that kills for 10 minutes, then back on 10 minutes,and also works with crontab. I am brand new to this so please have mercy. I don't know if any semblance of this (below) can be used, but I tried. ssh keys are installed. Thanks.


i=1
while [ "$i" -ne 0 ]
do
i=./cron5
ssh localhost
done

Thanks Again, j.
 
Old 12-18-2022, 11:48 AM   #2
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,154

Rep: Reputation: 394Reputation: 394Reputation: 394Reputation: 394
What is the ultimate goal here? You may be asking the wrong question.
 
Old 12-18-2022, 11:49 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,776

Rep: Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996
Quote:
Originally Posted by jefferj54 View Post
..that kills for 10 minutes, then back on 10 minutes,and also works with crontab. I am brand new to this so please have mercy. I don't know if any semblance of this (below) can be used, but I tried. ssh keys are installed. Thanks.
Code:
i=1
while [ "$i" -ne 0 ]
do
i=./cron5
ssh localhost
done
You're 'brand new' to scripting...when you asked about scripting and loops ten years ago???
https://www.linuxquestions.org/quest...op-4175475472/
https://www.linuxquestions.org/quest...op-4175474340/

And your question and associated code make no sense...you want a script that "kills for 10 minutes"? What does that mean? What is your actual goal here? Because it appears as if all you're doing is trying to SSH into your local host...which is where you ALREADY ARE....so why use SSH?
 
Old 12-18-2022, 11:49 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,793

Rep: Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952Reputation: 5952
Without knowing what your are trying to accomplish nor what cron5 does it is impossible to provide advice.
 
1 members found this post helpful.
Old 12-18-2022, 11:54 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,368
Blog Entries: 3

Rep: Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771
Quote:
Originally Posted by jefferj54 View Post
..that kills for 10 minutes, then back on 10 minutes,and also works with crontab. I am brand new to this so please have mercy. I don't know if any semblance of this (below) can be used, but I tried. ssh keys are installed. Thanks.


i=1
while [ "$i" -ne 0 ]
do
i=./cron5
ssh localhost
done

Thanks Again, j.
If you have the keys in the agent, you won't need to re-enter the passphrase each time.

Code:
while true
do
    timeout 600 ssh \
        -i ~/.ssh/some_key.ed25519 \
        -o IdentitiesOnly=yes \
        -l jeffer54 \
        localhost
    sleep 600
done
See "man timeout", "man sleep", and the IdentitiesOnly option in "man ssh_config". Speaking of the configuration file, you might also be interested in adding some configuration options in ~/.ssh/config

Then put that in a script and call the script from cron.

Getting the keys with passphrases to work with cron is a bit more advanced because you'll have to have an agent running manually loaded with the key and point to the right socket for it in the script. Try getting the script working outside of cron first.

What problem are you trying to solve?
 
Old 12-18-2022, 06:14 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,776

Rep: Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996
Apparently, the OP saw fit to come back and re-open a thread that had been closed for *SEVENTEEN YEARS* to complain about the quality of answers they received:
https://www.linuxquestions.org/quest...ml#post6398793

OP, if you'd like better answers, ask better questions. Read the LQ Rules, and "Question Guidelines", about showing your own efforts. Claiming to be 'new' at scripting (when you asked about it a decade earlier), doesn't show us those efforts. You were asked what you mean by a script that "kills" for a few minutes, asked why you were trying to SSH into your local host (?), etc. But instead of coming back here to provide such details and explain things, you took that time to complain.

We aren't here to write your scripts for you, nor should we have to pry information out of you. You claim to not need 'nonsense'...neither do we.

Last edited by TB0ne; 12-18-2022 at 06:15 PM.
 
1 members found this post helpful.
Old 12-18-2022, 10:56 PM   #7
jefferj54
LQ Newbie
 
Registered: Aug 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Mr. TB ONE...

...If you cannot answer questions without having your butt up on your shoulders, then you are in the wrong occupation. Try the N.F.L. I want to thank the one person who attempted to answer my question. P.S., the question was somewhat different as was years ago, because the question also had to do with Crontab. You know what? Block me from this sorry forum so that I don't waste my time removing MYSELF!

jefferson.
 
Old 12-19-2022, 12:05 AM   #8
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,772

Rep: Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770
Quote:
Originally Posted by jefferj54 View Post
...If you cannot answer questions without having your butt up on your shoulders, then you are in the wrong occupation. Try the N.F.L. I want to thank the one person who attempted to answer my question. P.S., the question was somewhat different as was years ago, because the question also had to do with Crontab. You know what? Block me from this sorry forum so that I don't waste my time removing MYSELF!

jefferson.
#1 No one is here for their "occupation", this is a community. No one is paying for professional support here. There is no basis for judging anyone's occupation or fitness within that occupation.

#2 No one suggested blocking or removing you, except you.

#3 Posting a question in the "Newbie" forum when you have been on since 2013 does seem very odd. You see nothing strange or inappropriate about that? Why insult someone who pointed that out, or the forum itself? You misused the forum a bit, but that can be fixed. Why not request the post be moved to a more appropriate location?
 
1 members found this post helpful.
Old 12-19-2022, 01:54 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,368
Blog Entries: 3

Rep: Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771Reputation: 3771
Quote:
Originally Posted by jefferj54 View Post
... because the question also had to do with Crontab
Get the script working without cron first. If #5 is not a good guess, then please provide more information. More information would be good anyway, so it would be good if you could explain what you are trying to do with the script. There doesn't seem to be much point to connecting to local host for 10 minutes every 20 minutes.

Once your script is working without cron, then you can look at launching an extra agent with a designated socket for the script to refer to. Otherwise a locked down key is the way to go but for that you'd have to give a good idea about what's happening on the server end.
 
Old 12-19-2022, 05:57 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,068

Rep: Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363Reputation: 7363
I wanted to help you, but I have no any idea how. I mean I don't really understand where did you stuck, what is your problem. Please give us more details.
https://www.catb.org/esr/faqs/smart-...html#beprecise
 
Old 12-19-2022, 08:03 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,776

Rep: Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996Reputation: 7996
Quote:
Originally Posted by jefferj54 View Post
...If you cannot answer questions without having your butt up on your shoulders, then you are in the wrong occupation. Try the N.F.L. I want to thank the one person who attempted to answer my question. P.S., the question was somewhat different as was years ago, because the question also had to do with Crontab. You know what? Block me from this sorry forum so that I don't waste my time removing MYSELF!
Certainly CAN answer the question...if we even knew what the question WAS. You STILL have not explained your issue, what it is you're trying to accomplish, how CRON even fits into this, etc. How, exactly, do you think we'll be able to answer you when *FIVE DIFFERENT PEOPLE* have all asked for the same information???

Scheduling a job for every 10 minutes in cron is trivial...and has ZERO to do with whatever program cron executes. You were asked for more information in your first question about a bash loop, and never followed up.
https://www.linuxquestions.org/quest...op-4175474340/

...and TOLD PEOPLE what answers you'd accept in your other:
https://www.linuxquestions.org/quest...op-4175475472/

A simple loop is not different than it was ten years ago. And since we don't know what you mean by needing a program that 'kills' for ten minutes (kills what??) then back on ten minutes, to SSH into the machine the script is on (again, why?) to do some function....we can't give you any advice. And at this point, given your attitude, it's unlikely anyone would want to. Have your skills not progressed ANY in a decade?

Last edited by TB0ne; 12-19-2022 at 08:25 AM.
 
Old 12-20-2022, 09:38 AM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,259

Rep: Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338
The point, that you haven’t posted enough information, stands.

What are you trying to actually accomplish here? Is it availability-monitoring?

Last edited by dugan; 12-20-2022 at 05:06 PM.
 
1 members found this post helpful.
  


Reply



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
In a for loop that operates on multiple servers, need both the options to enter the password or to skip to next server in loop rajkamalhm Linux - Newbie 7 06-08-2016 09:28 PM
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Bash script issue (for loop inside a loop) Mperonen Programming 3 08-08-2013 02:14 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 05:17 PM
while loop or for loop? mijohnst Programming 18 11-21-2005 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:56 AM.

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