So I'm bangin my head against the wall on this one, and honestly think I'm missing something simple. I'm also thinking that my issue is either something wrong with the herdoc or something wrong with how I'm using STDIN.
Anywho, when I run the following script on the command line(yes running as root), instead of printing to the file, it just prints to STDOUT, which is confusing the hell out of me.
sub do_stuff {
my $resp = <STDIN>;
my $service_file = <<END_FILE;
[Unit]
Description = tc hack for perist across reboot
After = syslog.target network.target nss-lookup.target
[Service]
Type = simple
ExecStart = /etc/tc/tcconfig.sh
ExecReload = /bin/kill -HUP \${MAINPID}
ExecStop = /bin/kill -INT \${MAINPID}
TimeoutSec = 30
Restart = on-failure
LimitNOFILE = 32768
[Install]
WantedBy = multi-user.target
END_FILE
my $service_path = '/etc/systemd/system/multi-user.target.wants/tc.service';
open(my $sfile, ">", $service_path)
|| die "can't open file for write ($service_path) $!";
print $service_file;
close $sfile;
}
And the output of this to the command line is:
[Unit]
Description = tc hack for perist across reboot
After = syslog.target network.target nss-lookup.target
[Service]
Type = simple
ExecStart = /etc/tc/tcconfig.sh
ExecReload = /bin/kill -HUP ${MAINPID}
ExecStop = /bin/kill -INT ${MAINPID}
TimeoutSec = 30
Restart = on-failure
LimitNOFILE = 32768
[Install]
WantedBy = multi-user.target
The output is being printed to the command line rather than the file. No idea why. Any help much appreciated!
Cheers