Questions Tagged With shell-scripthttp://linuxexchange.org/tags/shell-script/?type=rssquestions tagged <span class="tag">shell-script</span>enThu, 23 Apr 2015 17:12:38 -0400how to define variable in sshhttp://linuxexchange.org/questions/3525/how-to-define-variable-in-ssh<p>I need to use <code>ssh</code> to send command to different computers to run programs. Can I define a variable of <code>Directory</code> and <code>program</code> in front of this shell script? Then, I do not need to write them every time?</p> <p><code>host_list=("c15-0330-10.ad.mtu.edu" "c15-0330-11.ad.mtu.edu" "c15-0330-12.ad.mtu.edu")</code> <code># I have multiple programs</code> <code># program=c("L_1","L_2","L_3")</code> <code>ssh -f "${host_list[0]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_1.R&gt; L_1_sh.txt;echo "The job L_1 is finished" |mutt "zwang10@mtu.edu" -s "The job L_1 is finished"'; ssh -f "${host_list[1]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_2.R&gt; L_2_sh.txt;echo "The job L_2 is finished" |mutt "zwang10@mtu.edu" -s "The job L_2 is finished"'; ssh -f "${host_list[2]}" 'set Directory="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"; cd $Directory &amp;&amp; nohup Rscript L_3.R&gt; L_3_sh.txt;echo "The job L_3 is finished" |mutt "zwang10@mtu.edu" -s "The job L_3 is finished"';</code></p>zwang10Thu, 23 Apr 2015 17:12:38 -0400http://linuxexchange.org/questions/3525/how-to-define-variable-in-sshterminalshell-scriptsshA query?Green Hostinghttp://linuxexchange.org/questions/3478/a-querygreen-hosting<p>Fine, I simply purchased a domain-name from domain.com that was irish And understand im on the best way to get it hosted, questioning Understand this is about 4 pages website, would you guys understand where I could get even free hosting or affordable sponsor????</p>FrogicapTue, 13 Jan 2015 04:35:59 -0500http://linuxexchange.org/questions/3478/a-querygreen-hostingshell-scriptHOW TO USE ALL INODES IN MY SYSTEMhttp://linuxexchange.org/questions/3447/how-to-use-all-inodes-in-my-system<p>MY UBUNTU PC HAS THE FREE INODES I WANT TO USE ALL OF THEM WITH A AUTOMATIC SHELL SCRIPT. HERE ONE THING I DON'T WANT TO CREATE ANY FILE THAT MEANS WITHOUT CREATING ANY FILE I HAVE TO USE ALL FREE INODES IS THERE ANY COMMAND ? OR SCRIPT?</p>ashokkrishnaFri, 24 Oct 2014 10:36:39 -0400http://linuxexchange.org/questions/3447/how-to-use-all-inodes-in-my-systemshell-scriptsecuritydebianbashlinuxPassing a stream to a bash functionhttp://linuxexchange.org/questions/3098/passing-a-stream-to-a-bash-function<p>Hello I have a problem, I need to create a BASH function that I can pass a stream to NOT A FILE. Here is the function: function ff() { cat /etc/group | fgrep -f "$1" }; When I run it like so</p> <pre><code>ff &lt;( echo some_user ) </code></pre> <p>I get an error saying "fgrep: /dev/fd/63: No such file or directory", instead of "some_uer:x:0:"</p> <p>Much Appreciated!</p>RoccoMon, 13 May 2013 17:49:03 -0400http://linuxexchange.org/questions/3098/passing-a-stream-to-a-bash-functionshell-scriptbashIs there any website having command line environment of Linux, for practicing commands?http://linuxexchange.org/questions/3086/is-there-any-website-having-command-line-environment-of-linux-for-practicing-commands<p>I was wondering whether I could practice LINUX commands and shell scripting, online, over a website which could provide me an editor to practice them. And I know that probably the easiest thing to do would be to download a Linux LIVE CD and then practice shell scripting, but apart from it, I want to practice them online, anywhere I want, anytime I want and on any system, without bothering about booting from a LIVE CD. Thanks.</p>AvianWed, 10 Apr 2013 03:41:49 -0400http://linuxexchange.org/questions/3086/is-there-any-website-having-command-line-environment-of-linux-for-practicing-commandsshell-scriptlinuxIs there any shell script or software available to watch a CSV file?http://linuxexchange.org/questions/2905/is-there-any-shell-script-or-software-available-to-watch-a-csv-file<p>I am using CentOS 5.5. There is a CSV file in a particular directory(/somewhere/somefile.csv) where a software continuously appending comma separated row(s) of data time to time and the file size is growing big (currently it's 50MB+). </p> <p>My idea is to create a demon to watch the CSV file. Whenever any row(s) of data appended in that CSV file the demon will read the last appended row(s) and create/write it in a separate text file by date. </p> <p>I would like to know:</p> <ul> <li>Is there any shell script/software available on this regards to watch a CSV file?</li> <li>Is there any better idea or solutions other then create a demon?</li> </ul> <p>I have googled tons of time but didn't find any good idea/solution(s). Please help. </p> <p>Thanks in advance.</p>tanveerWed, 18 Jul 2012 03:23:26 -0400http://linuxexchange.org/questions/2905/is-there-any-shell-script-or-software-available-to-watch-a-csv-fileshell-scriptcentosLogging bash scriptshttp://linuxexchange.org/questions/2647/logging-bash-scripts<p>Hi all,</p> <p>Is there an efficient way to log all the commands being executed from a shell script?</p> <p>For example if I have in my script:</p> <pre><code> firstLoop=$(losetup -f) losetup $firstLoop $my_vol </code></pre> <p>is there a way to automatically log the command (may be by 'set'ting some options) being executed and the result from the command into a log file. Currently I am performing it by passing the command to a shell function, log the command+arguments into a log file and execute the command from the command line by 'tee'ing it into the log file. I have given the function below:</p> <pre><code>ExecuteCommand(){ retVal=0 # LogMessage is another function that writes the given string into the log file LogMessage "-------------- Command Start ------------------------------------------------" LogMessage "Command = $*" # Execute the command so that the output(and error) is redirected both to the stdout and # the logfile "$@" 2&gt;&amp;1 | tee -a ${logFile} for curr_ret_status in ${PIPESTATUS[@]} do retVal=${curr_ret_status} # Break the loop if it is not a success [[ $retVal -ne 0 ]] &amp;&amp; break done LogMessage "Return code is ${retVal}" LogMessage "-------------- Command End --------------------------------------------------" return $retVal } </code></pre> <p>With this approach my example script given above will become:</p> <pre><code> firstLoop=$(ExecuteCommand losetup -f) ExecuteCommand losetup $firstLoop $my_vol </code></pre> <p>Do I have to perform what I want only by this way? Or is there a standard efficient way to do this?</p> <p>Please let me know if you need more information in this regard.</p> <p>Thanks</p>GunaTue, 02 Aug 2011 05:55:54 -0400http://linuxexchange.org/questions/2647/logging-bash-scriptsshell-scriptbashScripting question regarding cut and/or awkhttp://linuxexchange.org/questions/1359/scripting-question-regarding-cut-andor-awk<p>I'm running into a slight quandary with this particular script I need. I have a used egrep to yank from a large number of config files the location parameter of various unity databases. I have that information in a script. For example, the data looks like:</p> <pre><code>/home/test/demo/new /home/test/demo/old /home/yikes/mydir/ss/new /home/yikes/mydir/ss/old </code></pre> <p>So, the problem is each location doesn't have a particular field I can cut with "/" as the delimiter, however, the second to last field in that string is what I want: demo and ss. Is there an easy way to script this. I want to basically spin through this flat file (290 lines), in a new file print out the complete path and then on the same line separated by a space the second to last field.</p> <p>The end result would look like:</p> <pre><code>/home/test/demo/new demo /home/test/demo/old demo /home/yikes/mydir/ss/new ss /home/yikes/mydir/ss/old ss </code></pre> <p>Thanks for the help!</p>AndyMon, 20 Sep 2010 01:28:12 -0400http://linuxexchange.org/questions/1359/scripting-question-regarding-cut-andor-awkshell-scriptawkcut