Programming :: Bash Script Critics Required?
Jan 16, 2011
As part of a package manager I am trying to build I am at the stage of checking if my system has the latest packages installed. To this end I would like some feedback on pieces that could be improved or perhaps alternatives that I can utilise. To the aficionados' of Perl, Python and the like, whilst I know these may be better suited to the task, the package manager is currently completely bash so I am trying to stay within this paradigm for the moment. I have edited this version slightly as it normally would tie in with the rest of my scripts which are not shown here. If there are any questions please ask and I will answer to the best of my ability:
[Code]...
View 7 Replies
ADVERTISEMENT
Sep 19, 2009
I want to search a directory recursively looking for new .rar/ .zip files. When a new file is found I want to extract the contents to another directory. To top things off would like to rename the source file as something like original.rar.extracted.
View 8 Replies
View Related
Feb 4, 2011
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
View 3 Replies
View Related
Jan 24, 2010
simple bash code:
Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do
[Code]...
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
View 10 Replies
View Related
Nov 26, 2008
I have a config file that contains:
my.config:
Code:
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
Here is my parse_cmd script:
Code:
View 3 Replies
View Related
Jul 25, 2011
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
View 5 Replies
View Related
Sep 20, 2010
I have several scripts in /etc/rcS.d/ directory which are required to run on start up.Now I have written a new script, and I want it to be run during the system start up itself (Not in any runlevel). SoI have given the default start as,# Default Start :SBut when I use the command : "update-rc.d test_script.sh defaults".....it is creating symbolic links to/etc/rc0.d /etc/rc1.d ..../etc/rc6.d.But I actually need a symbolic link in the /etc/rcS.d/ directory.Is there is any way to achieve this ( I tried manullay creating a link in /etc/rcS.d, but that is not running the script on system start up).
View 1 Replies
View Related
Feb 3, 2011
it's been a long time since I did coding in C, but thought to pick up a very old project again, just to show off what I have been working on ten years ago.I deducted my problem as follows:
Code:
#include <stdio.h>
#include <stdlib.h>
#define bit1 1
#define bit2 2
[Code]...
Why is it saying that bar->act is not a valid lvalue while both bar->act and the bit are cast to (long long)?
View 6 Replies
View Related
Jan 9, 2010
I would like to get the filename (without extension) and the extension separately. The best solution I found so far is:
Let FILE="thefilenameofsomefilesfor_instance.txt"
Code:
NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
View 5 Replies
View Related
May 31, 2011
I have written a script to run commands on remote servers, it is working fine. But when I am running "sudo commands" on the remote servers, it asks for me password after prompting for ssh password. I am unable to automate this password prompt (which is just after ssh password prompt). This is the function I am using to provide passwords
Code:
pass ()
{
cd $DIR/"$dt1"_"$dt"
/usr/bin/perl << 'EOF'
use strict;
[code]....
I want the same function to be used , when it expects for sudo passwords for any of the below lines:
Code:
[sudo] password for vikas: orPassword: This is my "cmd" file passed in pass () function.
Code:
ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 192.168.1.100 "bash rcmds"
This is my script output
Quote:
[vikas@box1 ~]$ ./rscript.sh
++ rm -rf /home/vikas/May_31
++ mkdir -p /home/vikas/May_31
++ set +x
[code]....
how to automate the password prompt required for sudo commands.
View 8 Replies
View Related
Jun 10, 2010
I'm in the process of debugging and compiling about sixty FORTRAN 95 programs and could use a little bit of your help before my brain is fried and fingers are cramped. Thanks for your time!
I receive the following errors:
Here is my code:
View 5 Replies
View Related
Jul 4, 2010
I've recently starting dabbling with python and gtk/cairo bindings. Can anyone point me to a quick and easy way to convert a colour value from hex (e.g. #FF8000) into the format required by the set_source_rgb function?E.g. I have this:
Code:
cr=area.window.cairo_create()
cr.set_source_rgba(0.5,0.5,0,0.8)
[code]....
View 3 Replies
View Related
Mar 31, 2011
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i
do
find $i -type f -name '*.txt'
done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
View 10 Replies
View Related
Jan 29, 2011
I am trying to write a bash script that sources another bash script. Essentially, I need a few lines to check to see if a certain variable is set. If not, I set it manually, and then source a scripts with that variable in the path. I wrote a test script to try it, but for some reason the last line does not work. Here is what I wrote:
#!/bin/sh
source ~setupdir/setup.shrc #just a test, this line works
echo ${#SETUP} # prints 0 if setup is not set, which it isn't
if [ ${#SETUP} -eq 0 ]
then
SETUP="~setupdir"
fi
echo $SETUP # prints ~setupdir
[Code]...
View 5 Replies
View Related
Jul 13, 2011
i'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability
View 12 Replies
View Related
Mar 25, 2011
I have beat this enough and don't get what should have been a very simple thing to do. I build a variable;
Code:
CLIST=java,lua,python,php,perl,ruby,tcl
CLIST will be used by another bash script but I need to replace the commas with a space. I
[code]...
View 2 Replies
View Related
Dec 4, 2010
Creating script that converts hex to dec. But without using bc calculator or other methods that could convert it in one line. I need to make something like this script that converts dec to hex.
View 1 Replies
View Related
Apr 14, 2011
I have a basic awk script that can read a file named 'server_info' and output to the screen which fax lines are not working. Now I want to make the script execute commands instead of printing to the screen but I am having trouble... This is better explained by my code below:
test.sh Code: #!/usr/bin/awk -f
#
#The name of this script is test.sh
[code]....
View 1 Replies
View Related
Jul 14, 2011
Distro: Centos 5, PHP 5I have done a bit research on running bash commands from php and there was little success. This is my relevant php script
<?php
echo exec('pwd');
?>
[code]...
View 16 Replies
View Related
May 2, 2011
I am trying to build a function inside a script.
Code:
#!/bin/sh
#System commands and other configurable.
IPT=/sbin/iptables
IP6T=/sbin/ip6tables
IPST=/usr/sbin/ipset
MODP=/sbin/modprobe
GET=/usr/bin/wget
INT_NET=192.168.1.0/24 .....
I can find lots of tutorials in how to use if, then, else. However, how do I define a variable inside the function?
SEE>>
Code:
for c in $ISO
Also, am I using the 'test' command correctly( -/+ week as valid test)?
View 7 Replies
View Related
Feb 14, 2011
I'm somewhere between Novice and I have no idea what I'm doing with bash scripts. I'm writing a script to deploy images using partimage on my company's desktops, and while I have just about everything else figured out I have one issue left.Each of our 4 sites that will be using this disc will have a deployment server due to the fact that our sites have dedicated point to point links that our business traffic is conducted on. I need to be able to determine what site I'm at based onubnet and set a variable based on this determination. What I don't know is how to get the IP address in to an if statement, and properly determine subnet. For example:
192.168.1.0/16 - 192.168.7.0/16 need to use DEPLSERV01
192.168.8.0/16 - 192.168.16.0/16 use DEPLSERV02
192.168.17.0/16 - 192.168.24.0/16 use DEPLSERV03
View 1 Replies
View Related
Dec 27, 2008
I know it's a very silly question but could someone please explain the difference between "/bin/bash" & "/bin/sh" I was under the impression that both are same but following output on my Ubuntu 8.10 is making me raise my eyebrows.
Quote:
parag@station3:~$ ls -l /bin/bash ; ls -l /bin/sh
-rwxr-xr-x 1 root root 725136 2008-05-13 00:18 /bin/bash
lrwxrwxrwx 1 root root 4 2008-12-03 21:42 /bin/sh -> dash
parag@station3:~$
View 11 Replies
View Related
Apr 9, 2010
i want to run bash script on website.i still have to choose between unix hosting and windows hosting. my web hosting service offer Own Cgi - Bin PHP,ASP,MYSQL,MSSQL, and script schedule(cronejob). This is script
#!/bin/bash
#Store arguments from bash command line
fight=$1
support=$2
msg=rmsg
[Code]....
View 2 Replies
View Related
Nov 23, 2010
Having a problem with an unwanted redirection in in a function call. Although this isn't the function it does illustrate the problem:
Code:
#!/bin/bash
doat () {
ALL="sys1 sys2"
for Sys in $ALL;do
echo "---> $Sys <---";
echo $(eval echo $1);
[Code]...
figure out how to get the variable into the command without outputting to the file in the eval statement? So that ssh line that gets executed would look like the following to each iteration of the for loop:
Code:
ssh root@$Sys rpm -qa|sort > /trans/${Sys}-rpm-list.txt;
doat works when the incoming argument doesn't have any redirection in the command.
View 3 Replies
View Related
Jun 8, 2010
Is it possible to use Gambas as a GUI to read text string variables that are input by a user, and use the variables in a bash command?
I know how to do this simply with bash, but I want a GUI that little kids can easily use.
View 2 Replies
View Related
Feb 17, 2011
Just a simple BASH for loop to read the file path from a text file (clean.txt) echo the variable for debug purposes, and scp it to a server I have using port 50 for SSH.
I've already formatted the entries in clean.txt to handle spaces correctly, using sed replacement.
Example from the clean.txt file:
Code:
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/20 Auld Lang Syne.mp3
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/14 Deck the Stills.mp3
[Code]....
View 5 Replies
View Related
Jun 10, 2010
I have a script that generates a bunch of output, including the expansions details provided by: set -v -xI am trying to pipe everything that is displayed to a file, in addition to displaying it on the screen. I've managed to get stderr and stdout into the file, but the expansions are only printed to the screen. Here is what I have so far:sudo -u <user> source my_job.sh |tee my_log.txt 2>&1
View 2 Replies
View Related
Jul 8, 2010
I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?
View 2 Replies
View Related
Jul 16, 2010
I want to write the date & time and a text string to a file from crontab.The following line works fine in the CL:echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txtI installed in crontab and no text appears in the file that it is redirected to.The crontab entry looks like:* * * * * echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txtTried a version to just write to stdout....* * * * * echo $(/bin/date +"%F %T")" Some text"No date, time or text appears at the command line
View 5 Replies
View Related
Aug 11, 2010
I understand that $! is the PID of a command. For example:
Code: #!/bin/bash
myprogram &
echo "PID of myprogram is $!"
I'd like to send the output of "myprogram" to both console and to a log file using the "tee" command but I also want to store the PID of "myprogam". Something like this:
Code: #!/bin/bash
myprogram | tee ./logfile &
echo "PID of myprogram is $!"
The problem is that $! is now the PID of "tee" rather than the PID of "myprogram".
View 3 Replies
View Related