Linux User Group of Mauritius Promoting open source software in our beautiful island

16Dec/150

Vote for your favorite Bash logo

Posted by Ish

Chet Ramey, maintainer of GNU Bash, the popular shell that comes bundled with Linux distributions, announced earlier that he received new logo proposals for Bash. In his message on the bug-bash mail list, he invites Bash users to vote for their favorite among the three logo proposals that he received from Justin Dorfman.

new-bash-logo

Source: http://imgur.com/RTK89fX

Chet shared a Google form allowing people to cast their vote. I like the second proposal and voted for the same. At the time I voted the form recorded 12 responses, out of which the second logo received 11.

bash-logo-votes

If you’d like to see your favorite logo sport GNU Bash, cast your vote now :)

The post Vote for your favorite Bash logo appeared first on HACKLOG.

28Nov/150

Customize the shell prompt

Posted by Ish

During the week I confused the hostname of a friend’s machine to be his username. He has a MacBook Pro and the shell prompt in OS X displays like:

Hostname:CurrentDirectory User$

My openSUSE laptop has the following prompt and I like it this way:

ish@coffee-bar:~>

He then asked me how to customize the shell prompt. Now, the shell prompt consists of a set of characters that appear every time the shell is ready to accept a command; like we see above. In order to customize the shell prompt with information that we want to display we need to provide some special characters to the PS1 variable (PS stands for ‘prompt string’). Additional input can be provided through PS2, PS3 etc but that’s outside the scope of this post.

We can set the prompt temporarily trying various combinations of special characters by executing something like export PS1="[t w] $ " to see a prompt like [14:52:48 ~] $.

customize-shell-prompt

As we can see above different sets of special characters can be used to customize the shell prompt accordingly. The table below shows various special characters that can be used to further customize the shell prompt.

Variable Description
t Prints the current time in hours, minutes and seconds.
@ Prints the current time in 12-hour am/pm format.
$ Displays the user prompt ($) or root prompt (#), depending on which user you are.
h Prints the hostname of the computer running the shell.
H Prints the full hostname (e.g localhost.localdomain).
u Prints the current username.
w Displays the full path of the current working directory
W Displays only the current working directory base name (e.g /var/log/nginx will be shown as ‘nginx’ only).

To make the shell prompt customization permanent, the value of PS1 can be added to the .bashrc file in the user’s home directory (e.g /home/username/.bashrc).

The post Customize the shell prompt appeared first on HACKLOG.

Tagged as: No Comments
22Mar/150

Bash source file

Posted by Ish

While I had no particular reason why to code it in Perl or Python, I ended writing my scripts in Bash on this Sunday afternoon. No huge tasks were meant to be executed, just some database reading. However, all of the short scripts would be using common variables, namely regarding the DB credentials. Sourcing variables from an external file could be achieved using . filename or source filename.

A little heck comes when passwords containing special characters such as $ < > [] {} ` ' " | & ; * ? are used. In your source file you need to escape each of those characters using a backslash symbol.

For example we could have a configuration file db.conf as follows:

HOST=localhost
DBNAME=testdb
DBUSER=user001
DBPASS=!p@ssw0rd$

Now, let’s get the variables as follows:

#!/bin/bash
. db.conf
echo $DBPASS

Copy the above in a file named getSQLPass.sh and we run it.

bash-source-file

The backslash symbols do not get printed.

The post Bash source file appeared first on HACKLOG.

Tagged as: No Comments
25Oct/140

Shellshock: A survival guide

Posted by Ish

It’s been the hot talk since a few weeks. Well, the presentation was finally due today at the University of Mauritius. Scheduled for 13h00, however I reached at noon. Planned to meet Shelly first and explain her a little about Linux (in general) and then show her what’s Bash.… Read more ➡

The post Shellshock: A survival guide appeared first on HACKLOG.

Tagged as: No Comments
3May/140

MSCC – Let’s talk about Scripting

Posted by Ish

It was initially scheduled for last Saturday but upon request MSCC monthly meetup was re-scheduled for today. I thought that would give me sufficient time to craft some cool scripts that I could showcase during my presentation on Bash Scripting. Oh! I was wrong. I either didn’t get enough inspiration or simply I was lazy to write stuffs. Wait! How could I be lazy since I did get time to make some colorful slides. Ahaan … Inspiration then?

Back to topic, this morning Rajnee (a new LUGM recruit) texted & told me she could pick me up before going to the meetup. This was the first time she’d be attending an MSCC meetup. That was too cool, she picked me up around 10h00 & we arrived at the University of Mauritius a little before 10h30. On the way I called Ronny, he had some other priorities and might not show up. We initially planned to spare 15 minutes today & approve the new recruits of LUGM.

At UoM, I called up Yunus to find my way to Phase II, room 2.9. It wasn’t a tough task. I do know a little bit about UoM building layouts. Right infront of room 2.9, I saw Nayar and Aslam waiting. They reached earlier and inquired about the class. Seemed like it was occupied and it would be free as from 10h30. Fair enough for us. A short while later Daniel showed up followed by others.

Others? Who else?

Those who made it today:
Daniel, Nayar, Aslam, Rajnee, Ashmita, Yunus, Jagveer, Adarsh, Nadim, Pritvi, Saif, Jochen and his kids… oh, and me of course.

Ironically, the projector in room 2.9 was black & white. I was like whaaaat? No way. I spent time to make colorful slides, I can’t show those in B&W. We then moved to room 2.10 and 2.11. Same issue. Hopefully, Jochen brought his projector. So, we returned to room 2.9 and used his projector.

I presented my love for Bash first. As I mentioned earlier, due to lack of inspiration, I could not dedicate more time to script examples but I assured the presentation would be beneficial to new folks in Linux, giving them an insight about command-line. I talked about pipes, redirects, standard streams and how these can be coupled with Bash scripting.

My presentation (^^,)

Daniel brought a programmer’s approach and described the limits of scripting, as when should one shift to program something rather than scripting. He also showed us some syntax loopholes in Bash that could leave someone with bad code.

Daniel's slides

In the end, Jochen brought us PowerShell. We went back in history, discussed MS-DOS and Microsoft’s evolution to PowerShell. Yes, Microsoft has been slow on this decision. Questions sprouted along the way as Jochen proceeded with PowerShell talks. I shot about a server having just PowerShell, like no GUI, and yes that’s available with Microsoft Server Core. Pritvi shot about connecting to a headless server using PowerShell. Yes, indeed that’s possible too but it’s not as in SSH (if you might be thinking that way). Jochen also highlighted the similarities with Bash, like having cmdlets (a PowerShell feature) aliased to popular Bash commands like, ls, mv, rmdir, mkdir etc.

After the presentations some of us moved to Bagatelle to have lunch. Meetup thus ended on a happy note over tea, panini, pita bread, sandwiches and pasta.

MSCC Meetup - Presentation on Shell Scripting mscc-scripting-daniel mscc-scripting-jochen mscc-scripting-bagatelle-1 mscc-scripting-bagatelle-2 mscc-scripting-bagatelle-3

Photos taken on mobile by Nadim. Indoor ones came bad due to lighting.

The post MSCC – Let’s talk about Scripting appeared first on HACKLOG.

Tagged as: No Comments