You are not logged in.

Dear visitor, welcome to sourceserver.info. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • DeaD_EyE

    Administrator

    You have to register first, to connect to this user.

17

Shell-Code zum Frühstück

Rating:

by DeaD_EyE, Thursday, April 21st 2011, 8:13am

Ich wurde gefragt, wie das nochmal mit dem überspringen der Abfrage beim hldsupdatetool unter Linux funktioniert.

Es gibt dafür viele Ansätze. Einer ist z.B. das Umleiten von "Yes" direkt an das Programm hldsupdatetool.

Source code

1
echo "Yes" | ./hldsupdatetool.bin


Ein weiterer Ansatz wäre Here-Document:

Source code

1
2
3
./hldsupdatetool.bin <<HIER_IST_DAS_ENDE
Yes
HIER_IST_DAS_ENDE


Im Regelfall verwendet man EOF für END-Markierung:

Source code

1
2
3
./hldsupdatetool.bin <<EOF
Yes
EOF


Letztendlich ist Here-String genau die Lösung, nach der ich lange Zeit gesucht habe:

Source code

1
./hldsupdatetool.bin <<<"Yes"


Als kleines Häppchen noch ein Codingbeispiel, wie man es machen könnte:

Spoiler Spoiler

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
STEAMTOOLURL="http://storefront.steampowered.com/download/hldsupdatetool.bin"
STEAMTOOLFILE="hldsupdatetool.bin"
STEAMINSTALLDIR="/home/server/serverfiles"


#colors
RED="tput setf 4"
GREEN="tput setf 2"
NORM="tput op"

checkWritePath() {
	touch "$1/temp$$" 2> /dev/null || return 1
	rm "$1/temp$$"
	return 0
	}


getSteamInstaller() {
	cd "$2" 
	wget -q -nc "$1" || return 1
	return 0
	}

installSteamTool() {
	which uncompress > /dev/null || return 1 
	cd "$2"
	chmod u+x "$1"
	echo "Installiere steam"
	"./$1" >/dev/null <<<"Yes"
	[ -x ./steam ] || return 2
	echo -e "Aktualisiere steam \c"
	for (( n=2 ; n <= 4; n++ )); do
		echo -e "..\c"
		./steam &> /dev/null && break 
	done
	if ./steam &> /dev/null; then
		echo
		return 0
	else
		echo
		return 3
	fi
	}


checkWritePath "$STEAMINSTALLDIR" ||
	{ $RED; echo "Keine Schreibrechte auf "$STEAMINSTALLDIR""; $NORM; exit ;}

echo "Lade $STEAMTOOLFILE herunter"
getSteamInstaller "$STEAMTOOLURL" "$STEAMINSTALLDIR" ||
	{ $RED; echo "Download fehlgeschlagen"; $NORM; exit ;}

installSteamTool "$STEAMTOOLFILE" "$STEAMINSTALLDIR"
case $? in
	0) $GREEN; echo "Update des Steamtools erfolgreich"; $NORM ;;
	1) $RED; echo "Uncompress fehlt"; $NORM; exit ;;
	2) $RED; echo "Entpacken von steam fehlgeschlagen"; $NORM; exit ;;
	3) $RED; echo "Update fehlgeschlagen"; $NORM; exit ;;
esac

This article has been read 21,541 times.

Tags: here-doc, Here-String

Categories: Allgemein


Comments (2)

  • 2

    by Demelza (Monday, August 22nd 2011, 4:22pm)

    Wowza, problem selovd like it never happened.

  • 1

    by Tessie (Sunday, August 21st 2011, 3:27am)

    There is a critical shortage of informative atrciles like this.

Blog navigation

Next article

Bonding-Test

by DeaD_EyE (Sunday, May 29th 2011, 5:37pm)

Previous article

Waffen den Spielern beim Spawn automatisch geben

by DeaD_EyE (Tuesday, March 22nd 2011, 1:54pm)