• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

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

0
dann47
Asked:
dann47
  • 4
  • 3
1 Solution
 
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!
0
 
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.
0
 
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

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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?
0
 
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.
0
 
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.

0
 
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

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now