Reputation: 45
I'm new to HTML, and I was able to print a simple linux date command on the web browser by calling the below script. However I'm trying to display the contents of the variable v
on the web-browser and I cannot do it. What am I doing wrong? The batch file works fine when I run it from command line, in other words there were no errors.
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo "Today is $(date)"
v=`ssh -t -q jcrm16 ". ~/.profile;/opt/reuters/scripts/matt/adsuserlist"`
printf "$v"
# echo $(printf "$v") << tried this did not work
echo "</body>"
echo "</html>"
Upvotes: 1
Views: 228
Reputation: 124844
Instead of putting the output of an ssh
command in a variable and then displaying the value of that variable, it would be better to just let the output of ssh
be displayed directly:
#!/bin/bash
cat <<EOF
Content-type: text/html
<html>
<head></head>
<body>
Today is $(date)
EOF
ssh -t -q jcrm16 ". ~/.profile;/opt/reuters/scripts/matt/adsuserlist"
echo "</body>"
echo "</html>"
But that doesn't change the fact that using ssh
is a terrible terrible idea and you shouldn't do it.
In any case, your original script should work. Most probably it doesn't work because the ssh
itself doesn't work when used by your web server process.
Either way, use something else for your testing, not ssh
.
Upvotes: 1
Reputation: 2951
You need to close your <head>
block, and open your <body>
block, as such:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head></head>"
echo "<body>"
echo "Today is $(date)"
v=`ssh -t -q jcrm16 ". ~/.profile;/opt/reuters/scripts/matt/adsuserlist"`
printf "$v"
# echo $(printf "$v") << tried this did not work
echo "</body>"
echo "</html>"
Upvotes: 0