Questions Tagged With bashhttp://linuxexchange.org/tags/bash/?type=rssquestions tagged <span class="tag">bash</span>enFri, 24 Oct 2014 10:36:39 -0400HOW 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-scriptbashRunning bash file in sudo crontab seems to failhttp://linuxexchange.org/questions/3053/running-bash-file-in-sudo-crontab-seems-to-fail<p>I am trying to run the script below in a crontab to keep my ip upto date.</p> <pre><code>#!/bin/bash clear echo "my ip form opendns: " dig @208.67.222.220 myip.opendns.com +short `hostname` echo "----------------------------- " echo "" myips=$(dig @208.67.222.220 myip.opendns.com +short `hostname`) arryIP=(${myips// / }) echo "should have found my IP address now: ${arryIP[0]}" echo " " echo "updating home.houseofhawkins.com: " echo "----------------------------------" curl <a href="https://www.cloudflare.com/api_json.html">https://www.cloudflare.com/api_json.html</a> \ -d "a=rec_edit" \ -d "tkn=mycode" \ -d "id=myid" \ -d "email=myemail" \ -d "z=myzone" \ -d "name=home" \ -d "type=A" \ -d "content=${arryIP[0]}" \ -d "ttl=120" </code></pre> <p>echo "" echo "done updating home.houseofhawkins.com..."</p> <p>if I do </p> <pre><code>. /home/me/updateIp.sh </code></pre> <p>This script will run successfully, but if I put this into a crontab it will always fail:</p> <pre><code>*/1 * * * * . /home/jon/updateIp.sh &gt;&gt; /home/jon/updateIpScript.log </code></pre> <p>the log file will have:</p> <pre><code>my ip form opendns: 86.180.163.89 67.215.65.132 ----------------------------- </code></pre> <p>Not sure what is wrong</p>twiggySun, 03 Mar 2013 12:14:59 -0500http://linuxexchange.org/questions/3053/running-bash-file-in-sudo-crontab-seems-to-failcrontabbashhow to check in a bash script where the shell is run fromhttp://linuxexchange.org/questions/2953/how-to-check-in-a-bash-script-where-the-shell-is-run-from<p>hello everyone, I am fuzzy about how to set a command in a script to be run only when the shell is running within an X session.</p> <p>basically, in ~/.bashrc I set my keyboard maps as </p> <blockquote> <p>setxkbmap -layout 'us,gr' -variant 'altgr-intl,extended' -option grp:alt_shift_toggle</p> </blockquote> <p>If I am connecting through putty , or otherwise, and i just open a command prompt window, I DONT want this command to run. If on the other hand, i have an X session running (locally or remotely) I want this command to run.</p> <p>how can I do this checking in a bash script? Is there a bash environment variable I can be looking at? some other way?</p> <p>Thank you for your help</p>synthnassizerMon, 22 Oct 2012 19:05:15 -0400http://linuxexchange.org/questions/2953/how-to-check-in-a-bash-script-where-the-shell-is-run-fromxorgbashUnix Commands - Find helphttp://linuxexchange.org/questions/2900/unix-commands-find-help<p>I'm trying to learn UNIX commands and I'm playing this game to learn and I'm really stuck at the moment. I'm in a server through ssh and the directory is full of random files and folders and the password for the next level is inside one of the files. I have been told that the file has the following attributes:</p> <p>human-readable 1033 bytes non-executable</p> <p>I am guessing that I should use the 'find' command and I tried " find ! -executable " but that returned a load of files. The only human-readable help I can find in the manual or online is printing out the file sizes in human readable. So I'm a bit lost there?</p> <p>Also I did try " find ~ -size 1033b " but that returned nothing. But when I tried " find ~ -size -1033b " it returned every file in the directory.</p> <p>Any help would be appreciated. Thanks in advance.</p>nickcorinSun, 15 Jul 2012 20:26:39 -0400http://linuxexchange.org/questions/2900/unix-commands-find-helpbashlinuxwhere is .bashrc in Linux Mint 11 [SOLVED]http://linuxexchange.org/questions/2677/where-is-bashrc-in-linux-mint-11-solved<p>afternoon, Im using mint 11. Previous versions have a '.bashrc' file. This version doesn't. I would like to put some aliases or functions in .bashrc. I started a '.bash_aliases' file and it works . But where did the '.bashrc' file go to?</p>kaykavMon, 05 Sep 2011 18:52:56 -0400http://linuxexchange.org/questions/2677/where-is-bashrc-in-linux-mint-11-solvedmintbashlinuxLogging 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-scriptbashCan i switch to a timed out ssh session?http://linuxexchange.org/questions/2325/can-i-switch-to-a-timed-out-ssh-session<p>I got timed out of a ssh session. Is there a way I can switch back to it if it still exists?</p>electronbenderTue, 12 Apr 2011 14:54:27 -0400http://linuxexchange.org/questions/2325/can-i-switch-to-a-timed-out-ssh-sessionsshbashIs there a way to search a file looking for two or more words that appear in the file?http://linuxexchange.org/questions/1467/is-there-a-way-to-search-a-file-looking-for-two-or-more-words-that-appear-in-the-file<p>I'm looking to "grep" a file looking for matches only if 2 or more of the keywords are found.</p> <p>So, for example, I want to search a file for blah and foo but they are on separate lines of the file. I only want to know if the file contains both keywords. I realize grep may not be the solution for this; may need to write a script of some sort but grep or some equivalent would be much faster.</p> <p>More Info:</p> <p>I have a file that contains:</p> <pre><code>stuff blah explore morestuff explore here foo </code></pre> <p>I want to be able to search that file for to see if both blah and foo appear in the file.</p>AndyThu, 30 Dec 2010 17:12:19 -0500http://linuxexchange.org/questions/1467/is-there-a-way-to-search-a-file-looking-for-two-or-more-words-that-appear-in-the-filescriptbashsearch-filesBash Scripting Questionshttp://linuxexchange.org/questions/1464/bash-scripting-questions<p>Ok, I've got a basic bash scripting question, but the answer is so simple it eludes me.</p> <p>From my .bash_aliases file....</p> <p>PROBLEM 1:</p> <p><pre><code></p> <p># alias reboot-win-host='net rpc shutdown -S thehostname -U username -r -f -t 120 -c "This system will reboot in 2 minutes. Save any work now." &amp;&amp; echo Rebooting Remote Windows System' # alias reboot-win-ip='net rpc shutdown -I 111.111.111.111 -U username -r -f -t 120 -c "This system will reboot in 2 minutes. Save any work now." &amp;&amp; echo Rebooting Remote Windows System' #</p> <p></pre></code></p> <p>What variable(s) do I use for the hostname (or IP) and the username?</p> <p>I want to: $ reboot-win-host hostname-here username-here or $ reboot-win-ip ip-here username-here</p> <p>PROBLEM 2</p> <p>For these, I can't get them to work for whatever reasoning....</p> <p><pre><code> alias perm='stat -c '%A %a %n'' alias list-root-id='awk -F: '($3 == "0") {print}' /etc/passwd' alias install-date='ls /var/lib/dpkg/info/*.list -lht | tail -1 | awk '{print $6}'</p> <p>top 25 process/RAM usage alias top-proc='ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 25'</p> <p>Graphic connections to hosts alias hosts-connect='netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c \ | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i &lt; $1; i++) {printf("*")}; print ""}' </pre></code></p>RonWed, 29 Dec 2010 22:43:24 -0500http://linuxexchange.org/questions/1464/bash-scripting-questionsbashscriptinglucidhow to change dhcp-range using shell scirpt via Variablehttp://linuxexchange.org/questions/1153/how-to-change-dhcp-range-using-shell-scirpt-via-variable<p>Dear All,</p> <p>I have small query for Linux Shell Scripting , below is my requirement:</p> <p>I have configured dnsmasq.conf , and it is working fine , I want to create script which automatically change the configuration of sever based on small input from user:</p> <p>dhcp-range=192.168.4.200,192.168.4.230,2h </p> <p>From this line I want to change start range and end range by script,This IP will not be fix all the time so I can not use "192.168.4.200" in my script with sed , I want to put 192.168.4.200 (or any IP there on dhcp-range line with variable $startip) and 192.168.4.230 with (variable $endip) </p> <p>I tried using grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' and also tried with awk but till now no success.</p>Chetan DiwaniTue, 27 Jul 2010 14:26:06 -0400http://linuxexchange.org/questions/1153/how-to-change-dhcp-range-using-shell-scirpt-via-variablelinuxscriptingbashProcessing passed arguments in scripthttp://linuxexchange.org/questions/1130/processing-passed-arguments-in-script<p>I'm trying to decide between short and long options, such as:</p> <p>-h </p> <p>vs.</p> <p>--help</p> <p>Obviously there are packages that deal with this, particularly in shell and perl programming.</p> <p>Getopts, Getopts::Std, and Getopts::Long</p> <p>I would prefer to use both, both -h and --help being a call for a help/usage function, but that requires quite a bit more effort.</p> <p>So my question is, what are the pros and cons of both, while I like the readability of the long notation, it's also nice and cleaner to be able to use just the simple single character flags.</p>rfelsburgFri, 23 Jul 2010 15:37:51 -0400http://linuxexchange.org/questions/1130/processing-passed-arguments-in-scriptprogrammingscriptingsystem-administrationbashconfigurationAre there any Change Management Systems (CMS) for Linux?http://linuxexchange.org/questions/869/are-there-any-change-management-systems-cms-for-linux<p>I am curious to find out if there are any Change Management Systems available for Linux (free of course). I'd like to be able to make changes to common files I use but have the ability to "backout" those changes (version control). I have written some various shell scripts that do this in a very simple manner (cp existing file -> append date -> place in a different directory -> diff old/new and save that output) and perhaps that's enough but was hoping folks on here would know of same actual CMS tools out there.</p> <p>Thanks - Andy</p>AndyWed, 16 Jun 2010 19:28:56 -0400http://linuxexchange.org/questions/869/are-there-any-change-management-systems-cms-for-linuxshellbashautomationconfiguration-managementHow can I improve this install script?http://linuxexchange.org/questions/779/how-can-i-improve-this-install-script<p>This is a script I wrote that you can run right after you install Ubuntu 10.04LTS (Desktop Edition). It adds some 3rd party applications, repositories, configures iptables and so forth. One thing I'd like it to do is detect if it's being ran on a 32-bit or 64-bit system and then either download the w32codes or the w64codes accordingly.</p> <p>I'm also open to any other ideas and/or suggestions.</p> <p>I've updated this code a few times, incorporating suggestions from people to the point that there's more code than what I am allowed to paste here, si I've moved the code off-site to a Pastebin log at:</p> <p><a href="http://pastebin.com/3B9K5Fyp" rel="nofollow">http://pastebin.com/3B9K5Fyp</a></p> <p>1) Does anyone see anything else I can do too?</p> <p>2) Another thing I was thinking of adding was my own repository for files like fonts, images, PDFs, etc and loading them into the appropriate places .I do have a Lanchpad account, but I'm not a packager/programmer by nature. I'm a network / os / security guy, not a developer. I'd like to make some sort of all-inclusive *.deb file that people can download from my repo and it'd update wallpapers, documents, programs, etc.</p> <p>Right now as you can see, I'm using Dropbox as a repo of sorts.</p> <p>So in addition to my on-going question of how to improve the script and the above new things, I need to add this:</p> <p>3) Is there a way I can test my script without loading it onto a new PC? A sort of "simulation mode" per se?</p> <p>I've ran into a couple of issues where during the install, I must select choices (like to accept the EULA for Java, or to enable or disable a daemon, etc), and I'd like to automate that process somehow for testing purposes.</p> <p>Lastly, but most importantly, I'd like to thank everyone for their suggestions, as you have helped me make this a better script.</p>RonFri, 04 Jun 2010 17:43:13 -0400http://linuxexchange.org/questions/779/how-can-i-improve-this-install-scriptubuntuinstallscriptingbashlucidI made a google cli function for .bashrc - is there a better way to do this?http://linuxexchange.org/questions/439/i-made-a-google-cli-function-for-bashrc-is-there-a-better-way-to-do-this<ol> <li>install elinks</li> <li>put the following in your .bashrc</li> </ol> <p>function google { /usr/bin/links g:"$1 $2 $3 $4 $5 $6 $7 $8"; }</p> <ol> <li>use/examples:</li> </ol> <p>$ google 2*4 $ google 1 dollar in euros $ google translate aller $ google weather </p> <ol> <li>I cannot believe I have created the best way to do this?</li> </ol>joeTue, 11 May 2010 01:43:12 -0400http://linuxexchange.org/questions/439/i-made-a-google-cli-function-for-bashrc-is-there-a-better-way-to-do-thiscligoogleelinksbashbash defeated??http://linuxexchange.org/questions/80/bash-defeated<p>Ubuntu Breezy 5.10 (don't suggest an upgrade - it works!)</p> <p>I'm trying to set up a script which updates some software on the hard drive from a directory on a USB Flash drive.</p> <p>After I've plugged in the USB drive and seen it recognised by automount:</p> <p>ls -l /vol/USBDISKB </p> <p>OK - shows me the directory and files.</p> <p>-BUT_</p> <p>#!/bin/bash if [ -d /vol/USBDISKB ]; then echo "Found USB drive" else echo "Not found: USB drive!" fi</p> <p>doesn't see the USB drive. :-((</p> <p>P.S. I tried to edit so it looks like code. Really.</p> <p>18/04/10 08:54 GMT Well! I don't know are am pretty stupid but I don't seem able to add a comment in response. All I seem able to do is edit my original post :(</p> <p>The obvious typos you can put down to my newbieness.</p> <p>If you are interested on following this question there has developed a much bigger thread here:</p> <p><a href="http://www.linuxquestions.org/questions/linux-software-2/bash-defeated-802372/" rel="nofollow">LQ Thread</a></p>fopeteslFri, 16 Apr 2010 10:55:41 -0400http://linuxexchange.org/questions/80/bash-defeatedbashautoloaderscriptingprogramming