Running shell script via web frontend

Hello, I am currently in the process of creating a script to search through a number of config files and filter out through a grep for an ID. (Script attached)

Running this from a server terminal the script runs fine, however for ease of use I am wanting to put it onto a web frontend, via CGI. e.g. Main index page, linked to a CGI file which invokes the shell script.

When this is ran via the web frontend it is picking up ID the user inputs, and prints it back to the screen (so the script is working) however for some reason is not printing the list of clients.

Does anyone have any ideas?

#!/bin/bash
echo
read -p "Enter the competition id:" comp
#comp=`echo $input | awk -F'=' '{print $2}'`
echo
echo "*****************************************************************"
echo "*****************************************************************"
cat competitions.xml | grep "Competition id=" | awk -F'"' '{print $2, $4}' | grep $comp
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatchplus"
echo "*****************************************************************"
grep $comp soccermatchplus-fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp soccermatchplus-fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatchplus"}'
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatch"
echo "*****************************************************************"
grep $comp soccermatch-fixures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp soccermatch-fixures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatch"}'
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatchplus Summary"
echo "*****************************************************************"
grep $comp smp_summary_fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp smp_summary_fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatchplus Summary"}'
echo

Open in new window

LVL 7
dann47Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dann47Author Commented:
For reference this is the output via the server terminal;

root@magners:/var/tmp/scripts/xml_query# ./whogetswhat

Enter the competition id:100

*****************************************************************
*****************************************************************
100 Barclays Premier League
*****************************************************************
*****************************************************************
These clients receive comp id 100 via Soccermatchplus
*****************************************************************
3United, admedia, akn, alston_elliott, astro_malaysia, bbc, bbc2, bbc3, bbc4, bbc_ftp, bbc_html, bbcintweb, bbcintweb_ks, benewayoy, betsettler, bridgex_sportech, canbrit_scotson, champion_data, easyodds, edentix, espn_checkpage, espn_global, ess_china, ess_china_translator, ess_ipop, ess_ipop_chinese_translator, ess_ipop_dev, ess_lifetree, ess_mauj, ess_redbee, ess_zing, evertonfc, ezen, fantasy_stakes, fareastone, fastweb_littlewoods, fastwire_checkpage, flame_digital, flame_digital2, foneworx, football_stats, gamed, gbn_translator, granite, hkjc_ko, hkjc_ko_bup, hkjc_ko_grab, hkjc_live, hkjc_live_bup, hkjc_tms, hkjc_tms_bup, hkjc_tms_grab, icable_translator, iknowledge, iknowledge_sxtv, iknowledge_sxtv_lv, ioglobal, ipop_telkomsel, itn_setanta, kactus, kactus_bup, kyodo_news, littlewoods, live_tables, mad_group, marketingnet, matchday, matchday_dup, mnc, mnc_wireless_icms, msn, msn_singapore, mtel, mtel_dup, mtel_translator, mtel_translator_dup, mtn_contec, multi_sport, multi_sport_translator, nearu_search, netease, nobok, onmobile, pa_client_translator, pa_teletext, pa_teletext_primary, pa_teletext_secondary, planet, portsmouth, setanta_cognifide, setanta_cognifide_live, simpli, sina, sis, sms_messaging, soccernet, sportal, sportal_translator, sportal_uk_translator, sportal_us_translator, sports1on1, sports_international, sport_tv, spurs, starhub, sunderlandfc, supersport, taipei_fb, test_ftp, thaiquest, tmg_cms1_live, tmg_ftp_backup, tmg_rivals, touchline, translator, truevision, twii_manu, viigo, webdev_livematch, westham, willhills, willhills_primary, xml_translator,

123 clients take this competition via Soccermatchplus
*****************************************************************
*****************************************************************
These clients receive comp id 100 via Soccermatch
*****************************************************************
bet365, bet365_dup, bet365int, brandx, etg, fapl2, fbl365, fw_fapl_wap, h3g_dup, h3g_fest_new, h3g_hk, ism, reuters, soccernet, tables_test, tmg_cms1_live,

16 clients take this competition via Soccermatch
*****************************************************************
*****************************************************************
These clients receive comp id 100 via Soccermatchplus Summary
*****************************************************************
alphameric, arsenal_fc, bbc_motd, benewayoy, betdaq_dev, betdaq_prod, betdaq_test, bridgex_sportech, hkjc, hkjc_bup, hkjc_grab, kactus, kactus_bup, lvs, metro, nobok, onmobile, pikum, showtime, sis, thefa, think_plank, tv3, zone,

24 clients take this competition via Soccermatchplus Summary

And this is what happens in the web frontend;


*****************************************************************
*****************************************************************
*****************************************************************
*****************************************************************
These clients receive comp id comp=100 via Soccermatchplus
*****************************************************************


0 clients take this competition via Soccermatchplus
*****************************************************************
*****************************************************************
These clients receive comp id comp=100 via Soccermatch
*****************************************************************


0 clients take this competition via Soccermatch
*****************************************************************
*****************************************************************
These clients receive comp id comp=100 via Soccermatchplus Summary
*****************************************************************


0 clients take this competition via Soccermatchplus Summary


Hope this is some help!
Adam314Commented:
You are not using including the path's in any of the filenames.  When the webserver runs the script, the current directory is not necessarily the directory containing the script.

Try specifying the full path to all filenames.
dann47Author Commented:
Thanks Adam, I have just tried that (see code) but I get the same result via the web front end. Any ideas?

Could it be the shell I am using? I have tried /bin/sh also, however I get the same problem.
#!/bin/bash
echo
read -p "Enter the competition id:" comp
echo
echo "*****************************************************************"
cat /var/tmp/scripts/xml_query/competitions.xml | grep "Competition id=" | awk -F'"' '{print $2, $4}' | grep $comp
echo "*****************************************************************"
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatchplus"
echo "*****************************************************************"
grep $comp /var/tmp/scripts/xml_query/soccermatchplus-fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp /var/tmp/scripts/xml_query/soccermatchplus-fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatchplus"}'
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatch"
echo "*****************************************************************"
grep $comp /var/tmp/scripts/xml_query/soccermatch-fixures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp /var/tmp/scripts/xml_query/soccermatch-fixures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatch"}'
echo "*****************************************************************"
echo "These clients receive comp id $comp via Soccermatchplus Summary"
echo "*****************************************************************"
grep $comp /var/tmp/scripts/xml_query/smp_summary_fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | tr "\n" "," | sed 's/,/, /g'
echo
echo
grep $comp /var/tmp/scripts/xml_query/smp_summary_fixtures.sh | grep DEST_PREFIX | grep -v "#"| awk -F/ '{print $2}' | sort -u | wc | awk '{print $1,"clients take this competition via Soccermatchplus Summary"}'
echo

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Adam314Commented:
As long as you have /bin/bash, and it is executable, you should be fine.

Does the webserver user have access to all of the files?
dann47Author Commented:
It's executable via the server terminal, so I assume it should be OK to run via the web front end too?

Originally the scripts where owned by a normal user, and apache owned by root. I have changed ownership of the scripts to root also, however that didnt make any difference either.

I have also changed my html to use the base href tag to see if that made any difference, however I still have the same problem.
Adam314Commented:
The scripts just need to be executable by apache, it doesn't matter who owns them.

Then the files used by the scripts (/var/tmp/scripts/xml_query/competitions.xml, /var/tmp/scripts/xml_query/soccermatchplus-fixtures.sh, ...) need to be readable by apache, again - it doesn't matter who owns them.

dann47Author Commented:
Resolved this. The problem was due to shell\CGI conflict. A simple awk command (see below) and bobs your uncle!!

Thanks for all your help
#!/bin/bash
echo
read -p "Enter the competition id:" input
COMP=`echo $input | awk -F'=' '{print $2}'`

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.