how do i prevent $ from being commented out if no value is present? (Bash Script)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do i prevent $ from being commented out if no value is present? (Bash Script)
# 1  
Old 01-22-2012
how do i prevent $ from being commented out if no value is present? (Bash Script)

Hey guys,

I want to paste a code in a .php file via a bash script. I am on ubuntu 10.04.

The problem is if the values for $ aren't present, then all of them would be removed by the script.

An example of my script (I modified it for this thread to prevent it from being overly complicated)

Code:
#!/bin/bash
# Script to add a user to Linux system

echo "Please enter RPCnumber"
read RPCNumber
echo "Please enter SCGIuserport"
read SCGIuserport
echo "please enter username"
read username

cat >/var/www/rutorrent/conf/users/$username/config.php <<EOF

<?php
        // configuration parameters

        // for snoopy client
        @define('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0', true);
        @define('HTTP_TIME_OUT', 30, true);     // in seconds
        @define('HTTP_USE_GZIP', true, true);

        @define('RPC_TIME_OUT', 5, true);       // in seconds

        @define('LOG_RPC_CALLS', false, true);
        @define('LOG_RPC_FAULTS', true, true);

        // for php
        @define('PHP_USE_GZIP', false, true);
        @define('PHP_GZIP_LEVEL', 2, true);

        $do_diagnostic = true;
        $log_file = '/tmp/errors.log';          // path to log file (comment or leave blank to disable logging)

        $saveUploadedTorrents = true;           // Save uploaded torrents to profile/torrents directory or not
        $overwriteUploadedTorrents = false;     // Overwrite existing uploaded torrents in profile/torrents directory or make unique$

        $topDirectory = '/home/$username/Downloads/';                  // Upper available directory. Absolute path with trail slash.
        $forbidUserSettings = false;

        $scgi_port = $SCGIuserport;
        $scgi_host = "127.0.0.1";

        // For web->rtorrent link through unix domain socket
        // (scgi_local in rtorrent conf file), change variables
        // above to something like this:
        //
        // $scgi_port = 0;
        // $scgi_host = "unix:///tmp/rpc.socket";

        $XMLRPCMountPoint = "/$RPCNumber";            // DO NOT DELETE THIS LINE!!! DO NOT COMMENT THIS LINE!!!

        $pathToExternals = array(
                "php"   => '',                  // Something like /usr/bin/php. If empty, will be found in PATH.
                "curl"  => '',                  // Something like /usr/bin/curl. If empty, will be found in PATH.
                "gzip"  => '',                  // Something like /usr/bin/gzip. If empty, will be found in PATH.
                "id"    => '',                  // Something like /usr/bin/id. If empty, will be found in PATH.
                "stat"  => '',                  // Something like /usr/bin/stat. If empty, will be found in PATH.
        );

        $localhosts = array(                    // list of local interfaces
                "127.0.0.1",
                "localhost",
        );

        $profilePath = '../share';              // Path to user profiles
        $profileMask = 0777;                    // Mask for files and directory creation in user profiles.
                                                // Both Webserver and rtorrent users must have read-write access to it.
                                                // For example, if Webserver and rtorrent users are in the same group then the value$

?>
EOF

echo "Done!!"

The values highlighted in red would change depending on my input. However, the final result is that these values indeed change, however every other value with the symbol '$' infront of them, disappears!

Here is an example of the output:

Code:
#!/bin/bash
# Script to add a user to Linux system

echo "Please enter RPCnumber"
read RPCNumber
echo "Please enter RPCport"
read RPCport
echo "please enter username'
read username

cat >/var/www/rutorrent/conf/users/$username/config.php <<EOF

<?php
        // configuration parameters

        // for snoopy client
        @define('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0', true);
        @define('HTTP_TIME_OUT', 30, true);     // in seconds
        @define('HTTP_USE_GZIP', true, true);

        @define('RPC_TIME_OUT', 5, true);       // in seconds

        @define('LOG_RPC_CALLS', false, true);
        @define('LOG_RPC_FAULTS', true, true);

        // for php
        @define('PHP_USE_GZIP', false, true);
        @define('PHP_GZIP_LEVEL', 2, true);

         = true;
         = '/tmp/errors.log';          // path to log file (comment or leave blank to disable logging)

         = true;           // Save uploaded torrents to profile/torrents directory or not
         = false;     // Overwrite existing uploaded torrents in profile/torrents directory or make unique$

         '/home/$username/Downloads/';                  // Upper available directory. Absolute path with trail slash.
         = false;

         = $SCGIport;
         = "127.0.0.1";

        // For web->rtorrent link through unix domain socket
        // (scgi_local in rtorrent conf file), change variables
        // above to something like this:
        //
        //  = 0;
        //  = "unix:///tmp/rpc.socket";

         = "/$RPCNumber";            // DO NOT DELETE THIS LINE!!! DO NOT COMMENT THIS LINE!!!

         = array(
                "php"   => '',                  // Something like /usr/bin/php. If empty, will be found in PATH.
                "curl"  => '',                  // Something like /usr/bin/curl. If empty, will be found in PATH.
                "gzip"  => '',                  // Something like /usr/bin/gzip. If empty, will be found in PATH.
                "id"    => '',                  // Something like /usr/bin/id. If empty, will be found in PATH.
                "stat"  => '',                  // Something like /usr/bin/stat. If empty, will be found in PATH.
        );

         = array(                    // list of local interfaces
                "127.0.0.1",
                "localhost",
        );

         = '../share';              // Path to user profiles
         = 0777;                    // Mask for files and directory creation in user profiles.
                                                // Both Webserver and rtorrent users must have read-write access to it.
                                                // For example, if Webserver and rtorrent users are in the same group then the value$

?>
EOF

echo "Done!!"

How do i prevent all those $values from disappearing?

Last edited by xxxx; 01-22-2012 at 04:59 AM..
# 2  
Old 01-22-2012
Try using a \ in front of $
Code:
        \$scgi_port = $SCGIuserport;
        \$scgi_host = "127.0.0.1";

# 3  
Old 01-22-2012
Thank you tukuyomi.

This solved my issue. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Can I prevent a script from being viewed?

i've vi'ed some scripts in the past and when i did, my screen froze. i had to go to another terminal and kill the vi process before i was able to get back my screen. how can i replicate this behavior on purpose? i want be able to do this also if the file or script was doubled clicked, say... (17 Replies)
Discussion started by: SkySmart
17 Replies

2. Shell Programming and Scripting

Bash append values if keywords are present in the file

Hi Team, i have a web ui where user will be passing values and the output will be saved to a file say test with the following contents . These below mentioned values will change according to the user_input Just gave here one example Contents of file test is given below Gateway... (7 Replies)
Discussion started by: venkitesh
7 Replies

3. Red Hat

Any Help About this script how can i prevent client to use it ?

Hello i have server cpanel on centos 6 an there is a client used script to hack other accounts the script is like this _____ __________ <?php $auth_pass = "7815696ecbf1c96e6894b779456d330e"; $color = "#df5"; $default_action = 'FilesMan'; $default_use_ajax = true;... (1 Reply)
Discussion started by: jackmio
1 Replies

4. Shell Programming and Scripting

How to prevent a shell script from copy or read from Users

I have a script which do validation check and perform code migration from one env. to another, this is built for users/developers. How can I prevent this shell script from copy or read from users, as they can modify it and run it as per their requirement where as this has to be standard script and... (1 Reply)
Discussion started by: pramendra
1 Replies

5. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

6. Shell Programming and Scripting

Cron job to prevent simultaneous script

I'm using a shared server on Hostgator (Linux CentOS). I'm trying to set a cron job using the Control Panel that will check if its already running before starting a new one. I've tried the following... * * * * * && but I get this error emailed to me... /bin/sh: line 0: Any... (5 Replies)
Discussion started by: tech9821
5 Replies

7. Shell Programming and Scripting

script - how to prevent in parallel run

I have one shell script which is being accessed by many jobs at same time. I want to make the script such that , other job should wait for the script if script is being used by some other job. Is there any way to implement it in script level ? Gops (1 Reply)
Discussion started by: Gopal_Engg
1 Replies

8. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies

9. Shell Programming and Scripting

how to prevent multiple email notifications from monitoring script

Hi everyone, I am in the process of trying to decide the correct way to solve a particular scripting/email issue I have and would appreciate any advice. We have a cronjob running every 10 mins to check disk size on the server and if this exceeds a certain percentage then it will email a... (2 Replies)
Discussion started by: si_linux
2 Replies

10. UNIX for Dummies Questions & Answers

Prevent bash from interpretation :

I am using bash shell; my requirement is to run a long command. Now I have split this long command into a number of shell variables. Some of these shell variables contain special character ':' At the end, when the intended long command is executed as a series of small shell variables the ':'... (7 Replies)
Discussion started by: uday
7 Replies
Login or Register to Ask a Question