Programming :: Evaluating Bash Script Without Saving ?

Sep 5, 2010

I blame myself but I am lazy person. Now I am trying to learn a bit a bash scripting. But saving any script to see how it works is so boring. You know these exercises:

Code:

Now save this in a file - say helloworld.sh (haha), chmod and execute to see

Code:

Is there a way to execute text as a script? I mean

Code:

View 6 Replies


ADVERTISEMENT

Programming :: Bash - Expression Is Always Evaluating To True

Jun 7, 2011

This line if [[ $hamachi_reachable = true && $lan_reachable = true ]]; then is always evaluating to true. I gave two ips that are not valid, so that both variables would become false yet the whole expression is evaluating as true. With that set -x in there, I get this output.

Where am I going wrong?

Code:

View 11 Replies View Related

Programming :: Bash - Dynamiquely Evaluating Variable Names

May 23, 2011

I'll try to be clear but I think I'm in a mess with my code right now, so it may appear here too

Here is a function. The part I want you to see is the 'eval' sentence.

This works.

It evaluates ${SourceTxt} (which is $1), takes away a part of it and uses it as an array to put data in.

That's alright.

Code:

Now, later, I NEED to count the number of elements in the array(s).

So, I try to do something like....

Which gives me the evaluated name ('#txtFields_email_customers[@]' e.g)

Or

Which gives me nothing....

I was wondering if I was reaching the limits of bash in this kind of capabilities, or if there is a.... bash-like solution. I.e. a good solution

View 7 Replies View Related

Software :: Saving A Sound File With Bash?

Feb 2, 2011

I wanted to stream audio and save it into a file which I can then listen to at a later date.

Ive found a source that provides a m3u file. Example : [URL]

Is there anyway which I can pipe / save this audio stream into another file using just a standard bash shell.

View 3 Replies View Related

General :: SH Script Not Evaluating Variable?

Jun 21, 2010

I am trying to evaluate the variable HEADER to see if it contains "HTTP/1.1 200 OK" and if so, to do something. If not, do something else. (writing to files - see below).The variable is being set, as ALL of the URLs that I am evaluating are being put into bad_urls.txt with their response headers. I can't figure out what I'm doing wrong. I've tried modifying the line in question quite a bit, trying different things, including:

if [[ ${HEADER} =~ "HTTP/1.1 200 OK" ]]; then
if [[ ${HEADER} == "HTTP/1.1 200 OK" ]]; then
if [[ HEADER = "HTTP/1.1 200 OK" ]]; then

[code]...

View 5 Replies View Related

Programming :: Saving A Certain Variable And Using It In All The Classes?

Feb 4, 2010

facing a problem in declaring variables. i have a few classes like the one below...

Code:
#ifndef _FINANCE_H
#define_FINANCE_H

[code]....

View 1 Replies View Related

Ubuntu Installation :: Which Benchmark To Use For Evaluating/quantifying System Performance

Jul 16, 2011

I am running the newest linux (ubunbtu 11.04) on an old laptop (2.3 Ghz celeron, 760 mb ram, bios is the latest version). I don't expect it to perform well, it's not a fast processor.But.....it performs so poorly with linux...and I am beginning to wonder whether the machine is broken or malfunctioning. The processor utilization seems high at all times, but I am not sure what is normal/typical.Which of the many benchmark software packages should I use in order to quantify it's performance (or lack there of)? Are there web resources that will list benchmark values of various machines, so I can determine if my punch box is broken or whether it's just slightly slower than other similar machines?

View 3 Replies View Related

Ubuntu :: Saving Current Programming Before Upgrading?

Jun 7, 2011

I am writing this because I want to keep all of the things that I have now on my ubuntu 10.
4 computer and do not want to upgrade until I have some way of keeping all of the things that I currently have on it.Sohow so I make this happen? Should I try to load these program settings on a flash drive?

View 1 Replies View Related

Programming :: Python ConfigParser Not Saving Comments?

Jun 16, 2011

I have a lot of scripts in Bash and am 'converting' one of them to Python just to get to know how Python works. Up to now I'm loving it, the feel, the logic, the power, ...

1. I have a template file which will be filled in by a technician, meaning it's filled with comments (#) and variable = value combinations, where the technician needs to fill in the values needed under the section referring to the configuration he's performing. 2. After installing from DVD/ISO, the software RPMs get installed and there is a default configuration file containing variable = value combinations where the values need to be changed to the values indicated in the template file mentioned in 1.

In order to do this I played around (and Googled a lot) with ConfigParser. I can load the template, get whatever value I need, load the configuration file, set the new value to the correct variable and write the file.

I checked that the template and configuration files loaded (open()) contain everything, including comments. However when I write the configuration file all comments get lost.

Here's what I have so far: Class to create a fakesection header since ConfigParser needs sections and the configuration file doesn't have those.

Code:
class FakeSectionHead(object):
def __init__(self, fd):
self.fd = fd

[Code]....

View 3 Replies View Related

Programming :: Saving Serializable Object Within It's Own Class

May 12, 2011

I found out how to save an object using Serializable in JAVA, the standard however how can I set up my MainVariableList to have a function/method saveobject so it saves the object within it's own class, the below code compiles, however when I run it reports an error on startup but works, basically what do I use for the red line, how do I tell it what object is passed to the class?

View 1 Replies View Related

Programming :: Bash: Printing The Line Number In Bash Script?

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

Programming :: Bash Ctrl+c Tarp And Bash Read With Timeout?

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

Programming :: Mistake With Sed Espression Is Saving Part Of Pattern?

Jan 20, 2010

got a textfile with : as delimiters in between fields. e.g.1:2:3:4:5:6Thomas Cruise:Johnavid:Peter:Betty:JaneThe names may or may not contain white spaces.I am required to substitute any one of these names in the file with a new one inputted by user.e.g. to change John to Johnny, David to Beckham, etc. without touching any of the other names in the same line. Just one at a time.So here's the sed expression I was trying out with:

sed -i "s/<(.:.:)David>/$1Beckham/" names.txt
I also tried:
sed -i "s/<(.*)David>/<1Beckham>/" names.txt

[code]....

View 24 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

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

Programming :: Run Multiple Bash And Php Scripts From A Bash Script?

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

Programming :: Saving A PPM File - Binary Representation Of Unsigned Chars On The Harddrive

Apr 7, 2010

I am accessing a firewire camera using the libdc1394 library and saving the image as a PPM file, using the code below:

[Code].....

My question is whether the above code is portable. I presume it is, since the result is a binary PPM file which should be capable of being read across multiple computers with different architectures and different operating systems. But at the same time, all that the above code is doing is just saving the binary representation of unsigned chars on the harddrive, and there does not seem to be any reason why the binary representations of the unsigned chars will be identical across multiple computers.

View 1 Replies View Related

Programming :: Bash: Get Filename And Extension Using Bash?

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

Programming :: Saving File Data Using Python In An Embedded System In An Safe And Fast Way?

Apr 19, 2011

I am developing a program in a system where the Linux does not take care of the sync command automatically. So I have to run it from my application always I save some data in the disk, which in my case is a 2GB sdcard. It is true that I can make the operation system takes care of the syncronization, using a proper mount option, but in this case the programm's performance drops drastically. In particular I use the shelve module from Python to save data that comes from a socket/TCP connection and I have to deal with the potencial risk of the system being turned off suddenly Initially I wrote something like that to save data using shelve:

Code:

def saveData(vo)
fd = shelve.open( 'fileName' , 'c')
fd[ key ] = vo
fd.close()
os.system("sync")

But that takes too much time to save the data. Note that I use the sync from the OS every time I close a file to prevent data corruption in the case of the "computer" being turned off with data even in the buffer. To improve the performance I made something like that:

Code:

def saveListData( list )
fd = shelve.open('file_name', 'c')
for itemVo in list:
fd[itemVo.key] = itemVo
fd.close()
os.system("sync")

Thus, first I saved an amount of objects in a list then I open the file and save the objects. In this way I have to open the file just one time to save a lot of objects.However I would like to know if adding a lot of objects before closing the file would increase the risk of data corruption.I known that turning off the system after fd.close() and before os.sync may cause problems. But what about turning off the system after

Code:

fd = shelve.open('file_name', 'c')

but before fd.close()?

View 7 Replies View Related

Programming :: Bash Programming - Rename Files In A Loop?

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

OpenSUSE Network :: Firefox - "saving Image As" It Fails To Offer "saving Window"?

Feb 4, 2010

Having openSUSE 11.2, Firefox (latest release) is having some issues when comes to "saving image as", it fails to offer "saving window"? Konqueror works normal, what could be the problem with Firefox?

View 4 Replies View Related

Programming :: Write A Bash Script That Sources Another Bash Script?

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

Programming :: Bash Scripting To Programming?

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

Programming :: Sed A Variable In Bash?

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

Programming :: Bash Script HELP - Hex To Dec ?

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

Programming :: Can Use Bash Within An Awk Script

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

Programming :: Bash Command From PHP?

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

Programming :: Bash Function Using If / Then And Else

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

Programming :: Bash IF Using IP Subnets?

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

Programming :: Difference Between /bin/bash And /bin/sh?

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

Programming :: Run Bash Script On Web?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved