How to Make a Bash Script in Ubuntu
Write your script in the Text Editor of Your Choice. The first line will be
#!/bin/sh
Then type your other commands.
When you’re done, save. then you’d need to make the script executable with
chmod +x SCRIPTNAME.
you’d execute it with
./SCRIPTNAME
If you have ever done a lot of repetitive tasks on a Ubuntu Linux machine, Im sure you’ve wondered if there is a better way of doing things. For example, say I need to run a dozen or more command line commands. I could enter them in one by one or I can put them all in a single file and run it as a script.
When you run it all as a script, you save a lot of time. Today, I am going to show you how to make the most simple Ubuntu script you can find. It doesn’t use any variables, it just helps you run several commands at once. for example, we are going to create a simple script to
First, just you need to create the script file. For this just open a terminal and type:
gedit samplescript.sh
This will open gedit with a blank file named samplescript.sh. In the file, type the following:
#!/bin/sh echo 'welcome' firefox
Save this file. The first line identifies it as a shell script, the second line causes the script to print welcome on your screen when it’s run. After the echo, you can put in any command line you want to on the next line and it will run. For this example, we put the command firefox and when you run the file, it will open Firefox.
Next, run this command to make the file executable:
chmod 777 samplescript.sh
Now, to run the script, type this:
./samplescript.sh
Popular Mistakes Made by Joomla Extension Developers
Here’s the presentation of my colleague at Dioscuri.com at Joomla and Beyond 2010 Conference about popular mistakes made by Joomla extension developers.
Remove NULL values from PHP arrays with 1 line
I had an array with something like the following:
<?php $array_with_nulls = array ( [0] => [1] => test [2] => fun ). ?>
But I don’t want [0], the empty value in the array.
Remove NULL values only
<?php $new_array_without_nulls = array_filter($array_with_nulls, 'strlen'); ?>
Remove any FALSE values
This includes NULL values, EMPTY arrays, etc.
<?php $new_array_without_nulls = array_filter($array_with_nulls); ?>
How to Check if an Image URL Exist with PHP
Quick and easy PHP script to determine if image exists. The image you are checking for can be hosted on your site or externally.
This script is useful to display an alternate image if the original one does not exist.
<?php
if (@GetImageSize("http://www.gerald.comuf.com/wp-content/uploads/2011/03/toolbar_feed.png")) {
echo "image exists";
} else {
echo "image does not exist";
}
?>
Use this script instead if you don’t have GD installed:
<?php
if (@fclose(@fopen("http://www.gerald.comuf.com/wp-content/uploads/2011/03/toolbar_feed.png", "r"))) {
echo "image exists";
} else {
echo "image does not exist";
?>
How to Install Tripwire on Ubuntu
If you’re interested in Tripwire then let me be the first to welcome you to the world of paranoid system admins. Tripwire can be a vital tool in detecting a compromise of your system.
Tripwire generates a database of the most common files and directories on your system. Once it is generated, you can then check the current state of your system against the original database and get a report of all the files that have been modified, deleted or added.
This comes in handy if you allow other people access to your machine and even if you don’t, if someone else does get access, you’ll know if they tried to modify files such as /bin/login etc.
So lets install Tripwire. First you need to download it from
http://sourceforge.net/project/showfiles.php?group_id=3130&release_id=26024.
At the time of this update the current version is 2.3.1-2.
Once you’ve downloaded it move the tarball to /usr/local/src (I like to store all my source code there) and untar it by running the following command:
tar -zxvf tripwire-2.3.1-2.tar.gz
Change into the newly created directory and edit the install.cfg with your favorite text editor (nano, pico, joe vi etc). script. You’ll want to edit the following:
# The root of the TSS directory tree. TWROOT="/usr/TSS"
Change this to
TWROOT="/usr/local/src/tripwire-2.3.1-2"
# This sets the default text editor for Tripwire.
TWEDITOR="/bin/vi"
You can change this to whatever editor you prefer.
Once you have those changed, save the file and exit. Then run the ./install.sh script. It will list the OSes that Tripwire supports and will ask you if you want to continue with installation. Next up is the License Agreement. Read it and if you accept, type accept.
It will then list all the settings and ask you if you would like to continue, answer yes. Then it installs the files and prompts you for a passphrase to password protect the database. Choose it wisely. It will now generate your keyfile and then prompt you for a local passphrase and a site passphrase.
Once that is done, tripwire will be installed and you’re ready to customize the format of the database and finally create it. To customize the database, you will need to edit the /usr/local/src/tripwire-2.3.1-2/policy/twpol.txt file. Make sure you back it upbefore you start changing things in it.
What I would recommend doing is first generating the database using the default policy file. Once the database is generated, use tripwire to check against it and you will get a report of what is missing on your system, for example it checks for /lib/modules/preferred and if you don’t have that file it will let you know in the report. If you don’t remove useless items from the policy file, you’re report will be long and full of garbage that you don’t need to look at everyday and you will probably miss the things you should be looking for.
So to generate the database, run:
/usr/local/src/tripwire-2.3.1-2/bin/tripwire --init
It will ask you for your passphrase and once you enter it, it will start to generate the database. This will vary in time depending on how big your installation is, how fast your CPU is etc. Once the database is generated, you will want to check it to find out what you can remove from the policy file. To check the database and have it output to a file, run:
/usr/local/src/tripwire-2.3.1-2/bin/tripwire --check > /tmp/report.txt
It will then proceed to check your filesystem against the database and will create a file called report.txt in /tmp which will contain information on what Tripwire discovered.
Open up this file and look for anything that it said it couldn’t find. Log into another terminal and open up the twpol.txt policy file. Compare the two and remove anything not found one by one. Once you are done editing, you have to recreate the policy file, to do this run:
/usr/local/src/tripwire-2.3.1-2/bin/twadmin --create-polfile ../policy/twpol.txt
It will ask you for your passphrase, once you enter it, tripwire should create a new policy file. You can then go ahead and update and then check your filesystem once more to see if you got everything. If you install alot of things, you will probably want to update the database on a regular basis.
You can also set up a cronjob to check the filesystem every night or whenever you feel like it and it will email you the report. Here is the line in my /etc/crontab file for Tripwire:
03 2 * * * /usr/local/src/tripwire-2.3.1-2/bin/tripwire --check | /usr/bin/mail root -s "Tripwire Check" 2>&1
All in all Tripwire is a handy utility to have and I feel some sort of relief reading the report every morning.
8 Ways to Make Firefox Ridiculously Fast
Firefox has been outperforming IE in every department for years, and version 3 is speedier than ever.
But tweak the right settings and you could make it faster still, more than doubling your speed in some situations, all for about five minutes work and for the cost of precisely nothing at all. Here’s what you need to do.
Browsers are normally very polite, sending a request to a server then waiting for a response before continuing. Pipelining is a more aggressive technique that lets them send multiple requests before any responses are received, often reducing page download times.
To enable it, type about:config in the address bar, double-click network.http.pipelining and network.http.proxy.pipelining so their values are set to true, then double-click network.http.pipelining.maxrequests and set this to 8.
Keep in mind that some servers don’t support pipelining, though, and if you regularly visit a lot of these then the tweak can actually reduce performance. Set network.http.pipelining and network.http.proxy.pipelining to false again if you have any problems.
Large, complex web pages can take a while to download. Firefox doesn’t want to keep you waiting, so by default will display what it’s received so far every 0.12 seconds (the “content notify interval”). While this helps the browser feel snappy, frequent redraws increase the total page load time, so a longer content notify interval will improve performance.
Type about:config and press [Enter], then right-click (Apple users ctrl-click) somewhere in the window and select New > Integer. Type content.notify.interval as your preference name, click OK, enter 500000 (that’s five hundred thousand, not fifty thousand) and click OK again.
Right-click again in the window and select New > Boolean. This time create a value called content.notify.ontimer and set it to True to finish the job.
If you haven’t moved your mouse or touched the keyboard for 0.75 seconds (the content switch threshold) then Firefox enters a low frequency interrupt mode, which means its interface becomes less responsive but your page loads more quickly. Reducing the content switch threshold can improve performance, then, and it only takes a moment.
Type about:config and press [Enter], right-click in the window and select New > Integer. Type content.switch.threshold, click OK, enter 250000 (a quarter of a second) and click OK to finish.
You can take the last step even further by telling Firefox to ignore user interface events altogether until the current page has been downloaded. This is a little drastic as Firefox could remain unresponsive for quite some time, but try this and see how it works for you.
Type about:config, press [Enter], right-click in the window and select New > Boolean. Type content.interrupt.parsing, click OK, set the value to False and click OK.
Intrusive Flash animations are everywhere, popping up over the content you actually want to read and slowing down your browsing. Fortunately there’s a very easy solution. Install the Flashblock extension (flashblock.mozdev.org) and it’ll block all Flash applets from loading, so web pages will display much more quickly. And if you discover some Flash content that isn’t entirely useless, just click its placeholder to download and view the applet as normal.
As you browse the web so Firefox stores site images and scripts in a local memory cache, where they can be speedily retrieved if you revisit the same page. If you have plenty of RAM (2 GB of more), leave Firefox running all the time and regularly return to pages then you can improve performance by increasing this cache size. Type about:config and press [Enter], then right-click anywhere in the window and select New > Integer. Type browser.cache.memory.capacity, click OK, enter 65536 and click OK, then restart your browser to get the new, larger cache.
TraceMonkey is a new Firefox feature that converts slow javascript into super-speedy x86 code, and so lets it run some functions anything up to 20 times faster than the current version. It’s still buggy so isn’t available in the regular Firefox download yet, but if you’re willing to risk the odd crash or two then there’s an easy way to try it out.
Install the latest nightly build (ftp://ftp.mozilla.org/pub/firefox/nightly/latest-trunk/), launch it, type about:config in the address bar and press Enter. Type JIT in the filter box, then double-click javascript.options.jit.chrome and javascript.options.jit.content to change their values to true, and that’s it – you’re running the fastest Firefox javascript engine ever.
If you’ve a slow internet connection then it may feel like you’ll never get Firefox to perform properly, but that’s not necessarily true. Install toonel.net (toonel.net) and this clever Java applet will re-route your web traffic through its own server, compressing it at the same time, so there’s much less to download. And it can even compress JPEGs by allowing you to reduce their quality. This all helps to cut your data transfer, useful if you’re on a limited 1 GB-per-month account, and can at best double your browsing performance.
How to Make Super Hidden Files or Folders
1. Open a command prompt
Click Start button-> select Run -> type “cmd” ( Windows XP )
Click Start button-> type “cmd” in the seach box ( Windows 7 )
50 Tips To A User Friendly Website
Here is a list of 50 things that WE should keep in mind on every website that WE build to will improve our visitors experience on our website.
Adapted from: http://www.designinginteractive.com/design/50-tips-to-a-user-friendly-website/
Continue Reading | Comments Off
How to Speed Up Internet by 20% in Windows
Microsoft reserves 20% of your available bandwidth for their own purposes like Windows Updates and interrogating your PC etc..
You can get the 20% to speed up internet by:
How to Speed Up Folder Browsing in Windows XP
You may have noticed that every time you open my computer to browse folders that there is a slight delay. This is because Windows XP automatically searches for network files and printers every time you open Windows Explorer. To fix this and to increase browsing significantly: