`JSON_DATA=$(cat test.json 2> /dev/null); if [ ! -z "${JSON_DATA}" ]; then WEBADDRESS='"webaddress":'$(jq '.webaddress' <<< "$JSON_DATA") && echo $JSON_DATA | sed 's/'$WEBADDRESS'/"webaddress":"5.5.5.5"/g' | sponge test.json 2> /dev/null; fi;`;
`jq '.upnpconfigaddress = "$ip"' /opt/habridge/data/habridge.config | sponge /opt/habridge/data/habridge.config`;
1 2 3 4
my $ip = "1.2.3.4"; $foo = `FOO=\$(echo "\$HOME"); if [ ! -z "\${FOO}" ]; then BAR="\$FOO: $ip" && echo \$BAR;fi`; use Data::Dump qw(dump); dump $foo;
"/home/haj: 1.2.3.4\n"
1
2
3
4
5
6
7
$ip = ...;
$fileSize = getFileSize("/opt/habridge/data/habridge.config");
if($fileSize > 0)
{
`jq /opt/habridge/data/habridge.config... "$ip"... | sponge /opt/habridge/data/habridge.config`;
}
1 2 3 4 5 6 7 8
... my $ip = "1.2.3.4"; ... # Skript mit parameter aufrufen qx{ /usr/local/bin/script.sh "$ip" }; ...
1 2 3 4 5 6
#! /bin/sh # checks etc. selber einbauen IP="$1" # Dein Rest Shell Code hierhin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/perl use warnings; use strict; my $fh; # Reading one line from "test.json": open($fh, "<", "test.json") or die; my $JSON_DATA = <$fh>; chomp($JSON_DATA); close($fh); my $WEBADDRESS; my $ip = "5.5.5.5"; if ($JSON_DATA -ne "") { $WEBADDRESS="webaddress:jq.webaddress" . $JSON_DATA; $JSON_DATA =~ s/$WEBADDRESS/webaddress\:$ip/g; # Writing to "test.json": open($fh, ">", "test.json") or die; print $fh $JSON_DATA; close($fh); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl
use warnings;
use strict;
my $fh;
# Reading one line from "test.json":
open($fh, "<", "/opt/habridge/data/habridge.config") or die;
my $JSON_DATA = <$fh>;
chomp($JSON_DATA);
close($fh);
my $WEBADDRESS;
my $ip = "5.5.5.5";
if ($JSON_DATA -ne "")
{
$WEBADDRESS="webaddress:jq.webaddress" . $JSON_DATA;
$JSON_DATA =~ s/$WEBADDRESS/webaddress\:$ip/g;
# Writing to "test.json":
open($fh, ">", "/opt/habridge/data/habridge.config") or die;
print $fh $JSON_DATA;
close($fh);
}
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
#!/usr/bin/perl
use warnings;
use strict;
#my $fh;
# Reading one line from "test.json":
#open($fh, "<", "/opt/habridge/data/habridge.config") or die;
#my $JSON_DATA = <$fh>;
#chomp($JSON_DATA);
#close($fh);
#my $WEBADDRESS;
#my $ip = "5.5.5.5";
my $JSON_DATA = "";
if ($JSON_DATA -ne "")
{
#$WEBADDRESS="webaddress:jq.webaddress" . $JSON_DATA;
#$JSON_DATA =~ s/$WEBADDRESS/webaddress\:$ip/g;
# Writing to "test.json":
#open($fh, ">", "/opt/habridge/data/habridge.config") or die;
#print $fh $JSON_DATA;
#close($fh);
}
2019-07-29T10:08:34 introdevDanke, aber Dein Programm gibt Fehler aus: