Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Hilfe bei der Erstellung eines Shellscripts
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Tue Oct 02, 2007 7:58 am    Post subject: Hilfe bei der Erstellung eines Shellscripts Reply with quote

Hallo Zusammen,

ich bräuchte mal Hilfe bei der Erstellung einen Scripts.

Das Script soll abfragen, ob ein Rechner erreichbar ist oder nicht.

Das Ganze sollte ungefähr so aussehen:

ping -1 <rechner>
WENN erreichbar DANN echo "text1" SONST echo "text2"

Ist so etwas möglich, und falls ja, wie?

Ich bin über jeden Tipp dankbar.
Back to top
View user's profile Send private message
schachti
Advocate
Advocate


Joined: 28 Jul 2003
Posts: 3765
Location: Gifhorn, Germany

PostPosted: Tue Oct 02, 2007 8:04 am    Post subject: Reply with quote

Code:
ping -c 1 RECHNER 1>/dev/null && echo "ja" || echo "nein"

_________________
Never argue with an idiot. He brings you down to his level, then beats you with experience.

How-To: Daten verschlüsselt auf DVD speichern.
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Tue Oct 02, 2007 8:13 am    Post subject: Reply with quote

Wow, danke, das nennne ich doch mal echte "Express-Hilfe"

Ich hätte alledings noch eine Frage:

wie kann ich das Ganze in eine if/fi Scheile einbinden?

Also ich meine: WENN erreichbar DANN weiter im Script SONST exit
Back to top
View user's profile Send private message
schachti
Advocate
Advocate


Joined: 28 Jul 2003
Posts: 3765
Location: Gifhorn, Germany

PostPosted: Tue Oct 02, 2007 8:19 am    Post subject: Reply with quote

Code:

#!/bin/bash

if (ping -c 1 RECHNER 1>/dev/null); then
  echo "ja"
else
  echo "nein"
fi

_________________
Never argue with an idiot. He brings you down to his level, then beats you with experience.

How-To: Daten verschlüsselt auf DVD speichern.
Back to top
View user's profile Send private message
69719
l33t
l33t


Joined: 20 Sep 2004
Posts: 865

PostPosted: Tue Oct 02, 2007 8:19 am    Post subject: Reply with quote

Code:

#!/bin/bash

reachable() {
  echo "reachable"
}

unreachable() {
  echo "unreachable"
}

ping -c 1 RECHNER 1>/dev/null && reachable || unreachable
Back to top
View user's profile Send private message
69719
l33t
l33t


Joined: 20 Sep 2004
Posts: 865

PostPosted: Tue Oct 02, 2007 8:20 am    Post subject: Reply with quote

da war jemand schneller :p
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Tue Oct 02, 2007 8:26 am    Post subject: Reply with quote

Vielen Dank Euch Beiden.

Genau das habe ich gesucht.
Back to top
View user's profile Send private message
Necoro
Veteran
Veteran


Joined: 18 Dec 2005
Posts: 1912
Location: Germany

PostPosted: Tue Oct 02, 2007 9:25 am    Post subject: Reply with quote

schachti wrote:
Code:

#!/bin/bash

if (ping -c 1 RECHNER 1>/dev/null); then
  echo "ja"
else
  echo "nein"
fi

Warum benutzt du eine subshell? - Ohne die würde es doch auch funktionieren ...
_________________
Inter Deum Et Diabolum Semper Musica Est.
Back to top
View user's profile Send private message
schachti
Advocate
Advocate


Joined: 28 Jul 2003
Posts: 3765
Location: Gifhorn, Germany

PostPosted: Tue Oct 02, 2007 10:15 am    Post subject: Reply with quote

Das ist gedacht als Quick'n'Dirty Ansatz zum Ausprobieren (als eigenständiges "Programm"). Falls man das in ein eigenes Skript einbauen will, läßt man die magic line natürlich weg.
_________________
Never argue with an idiot. He brings you down to his level, then beats you with experience.

How-To: Daten verschlüsselt auf DVD speichern.
Back to top
View user's profile Send private message
Necoro
Veteran
Veteran


Joined: 18 Dec 2005
Posts: 1912
Location: Germany

PostPosted: Tue Oct 02, 2007 12:15 pm    Post subject: Reply with quote

ich meinte nicht die shebang, sondern das:
Code:
(ping -c 1 RECHNER 1>/dev/null)
- warum du hier eine neue shell aufmachst... () führt den Inhalt in einer Subshell aus - zum gruppieren nimmt man {} (und selbst das wäre hier nicht benötigt)
_________________
Inter Deum Et Diabolum Semper Musica Est.
Back to top
View user's profile Send private message
schachti
Advocate
Advocate


Joined: 28 Jul 2003
Posts: 3765
Location: Gifhorn, Germany

PostPosted: Tue Oct 02, 2007 12:34 pm    Post subject: Reply with quote

Ah, wieder was gelernt, danke. Da kommt halt der C- und Java-Programmierer durch. :lol:
_________________
Never argue with an idiot. He brings you down to his level, then beats you with experience.

How-To: Daten verschlüsselt auf DVD speichern.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum