Home Blog Page 741

Bash Tips for Linux Sysadmins

The Bash shell is a fundamental Linux tool and, in this era of containers and clusters and microservices, good old-fashioned Linux system administration skills are as relevant as ever. Today, we’ll learn about running other command shells, Bash built-ins, configuration files, and shell expansion.

Which Shells?

Run cat /etc/shells to see which command shells are installed on your Linux system. Your default shell is set in /etc/passwd:

$ cat /etc/passwd|grep carla
carla:x:1000:1000:carla,,,:/home/carla:/bin/bash

You can run any other shell you want by invoking it from your Bash shell:

carla@studio:~$ tcsh
studio:~> 

Then type exit to return to Bash.

What’s Inside Bash?

Run enable -a to see a list of your Bash built-in commands. Some of these duplicate GNU commands, such as printf, kill, and echo. The Bash versions are stripped-down, with fewer command options. Use the built-in command type to see which they are:

$ type -a kill
kill is a shell builtin
kill is /bin/kill

$ type -a type
type is a shell builtin

Bash executes built-ins first, so if you want the GNU commands, you have to use the full path, like this:

$ /bin/kill 7502

The help syntax for Bash built-ins is backwards:

$ help kill

Bash Configuration Files

There are several Bash configuration files, and they differ according to your Linux distribution, so you may not have all of these. The best way to learn what they do on your system is to read them. User-specific files are read first:

  • /etc/profile, system-wide user environment defaults, applied at login.

  • ~/.bash_login, user settings applied only at login.

  • ~/.bash_profile, user-specific configuration, applied at login.

  • ~/.profile is used when ~/.bash_profile and ~/.bash_login are not present.

  • ~/.bashrc is applied to non-login shells, so you don’t have to log in every time you open a terminal. Most distros place user settings here, and then call ~/.bashrc from login files such as ~/.bash_profile.

  • ~/.bash_logout contains settings applied at logout, such as clearing the console.

  • ~/.bash_history contains your Bash command history up to your configured limit. Commands that you have run are stored in memory until you close the terminal you are working in, and then written to the file. This is why, when you work in multiple terminals, your command history gets mixed up.

What is the size limit of your history file?

$ echo $HISTFILESIZE
2000

Where is this limit set?

$ grep -d skip 2000 .*
.bashrc:HISTFILESIZE=2000

Shell Expansion

Shell expansion is one the biggest sources of confusion for Bash users, so I hope this explanation will help you understand how it works and thereby be less vexed.

You see tilde expansion in filenames, for example ~/.bashrc. The tilde is a shortcut for /home/user.

Brace expansion generates arbitrary text strings. This is a slick way to create a batch of new directories quickly:

$ mkdir -p testdirs/{test4,test5,test6}

There must not be any spaces between your filenames.

Pattern matching uses *, ?, and [] as wildcards. The * matches any string. You probably use this already, for example *.jpg to find all JPG files, or all files that start with a string like catpic*.

Using ? matches any single character:

$ ls tes?t
tesst

Patterns enclosed in square braces have mighty matching powers. This matches any one of the three enclosed characters:

$ locate test[256]
test2
test5
Test6

Square brace expansion supports POSIX character classes: alnum, alpha, ascii, blank, cntrl, digit, graph, lower, print, punct, space, upper, word, and xdigit. Use digit to match any numbers:

$ ls test[[:digit:]]
test4:

test5:

test6:

$ ls test[[:digit:]]*
test666  test9file

test4:

test5:

test6:

alpha matches only letters:

$ ls test[[:alpha:]]*
tesst

The character classes are great shortcuts, and the above POSIX link describes how all of them work.

Command substitution replaces command names with command output. The backslashes at the ends of the lines format the command examples so that they fit the column width. If you copy and paste these examples, you can include the backslashes. If you want to remove them, make sure your command is all on one line:

$ echo "The current directory is $(pwd), the date and time are 
$(date), and my hostname is $(hostname)"
The current directory is /home/carla/testdirs, the date and time  
are Mon Jul 25 13:40:00 PDT 2016, and my hostname is studio

You can use any command or script, and you can combine commands:

$ echo "The usernames in my /etc/passwd file are $(awk -F":"  
'{ print $1 }' /etc/passwd)"

You can use command substitution to assign variables. You can run these commands individually or put them in a script:

$ CWD=$(pwd)
$ DATE=$(date)
$ HOSTNAME=$(hostname)
$ echo "The current directory is $CWD, the date and time are 
$DATE, and my hostname is $HOSTNAME"                                          
The current directory is /home/carla/testdirs, the date and time  
are Sun Jul 24 13:53:34 PDT 2016, and my hostname is studio

Here we are at the end again already. In this article, I’ve shown the basics of how to use some important Bash commands. Please see these other articles for more beginning Bash tutorials.

Sign up to receive one free Linux tutorial each week for 22 weeks from Linux Foundation Training. Sign Up Now »

Wal-Mart Proves Open Source Is Big Business

Open source, in the form of both software and hardware is big business—really big business. This past week, Wal-Mart Stores, one of the largest retailers in the world proved it once again when they announced that they would make their application lifecycle management tool OneOps available as an open source project. Why give away something that you created yourself that gives your company an advantage? Because companies like Wal-Mart and General Electric (with their Open Innovation initiative) are finding that proprietary is being beat by collaboration and openness.

Turning a company’s proprietary work into something shared in the market can reap benefits as others also help innovate and return new features and functionality to your work.

Read more at Forbes

Intel Puts Numbers on the Security Talent Shortage

The cybersecurity shortfall in the workforce remains a critical vulnerability for companies and nations, according to anIntel Security report being issued today.

Eighty-two percent of surveyed respondents reported a shortage of security skills, and respondents in every country said that cybersecurity education is deficient. 25% of organizations have lost proprietary data to cyberattacks. Also, 71 percent of respondents report that the lack of security skills does measurable damage to their organizations

Large Shortage of Cybersecurity Skills, Intel Security saysRead more at SDx Central

Agile 2016: How to Measure your DevOps Initiatives

You’ve heard the benefits of DevOps, and you’ve decided to move your teams to this way of working. But how do you know if you are doing it right? Metrics are key indicators for businesses to figure out whether or not they are making the right decisions, but often they aren’t choosing the right metrics to look at, according to Anders Wallgren, CTO of Electric Cloud.

He spoke at the Agile 2016 conference in Atlanta about the key DevOps metrics businesses should look into to determine failures or successes.

Read more at SDTimes

Mirantis to Fuse Kubernetes, CI/CD with Commercial OpenStack

In a move with serious implications for the lowest software layers of data center infrastructure, commercial OpenStack producer Mirantis this morning announced it is partnering with the two most important players in the infrastructure space — Google and Intel — to produce a new version of the OpenStack platform designed to run inside Linux containers (such as Docker), for deployment through Google’s Kubernetes orchestrator platform.

“We are containerizing all of the OpenStack services,” explained Boris Renski, Mirantis’ co-founder and CMO, in an interview with Datacenter Knowledge, “and making it possible to natively run OpenStack on top of Kubernetes — to make it be orchestrated by Kubernetes.” … What Renski is telling us is that Mirantis’ commercial OpenStack is itself will be deployed within containers, whose coordination with one another will be maintained using Kubernetes.

Read more at Data Center Knowledge

 

OpenVZ 7.0 Runs Linux VMs Like Containers

One of the original major proponents of container technology on Linux, OpenVZ — or Virtuozzo in its commercial edition — is releasing a new version of its container solution, packaged as a full-fledged Linux distribution.

The commercial edition of OpenVZ, called Virtuozzo (also the name of the company marketing the product), incorporates OpenVZ but adds enterprise-grade features not found in the open source release. Virtuozzo has a new release of its own alongside OpenVZ 7, named — appropriately enough — Virtuozzo 7.

Most of the big changes announced in OpenVZ 7.0 involve the packaging and deployment of the product. It’s now an entire standalone Linux distribution, with both the commercial Virtuozzo product and the free OpenVZ distribution based on the same kernel.

Read more at InfoWorld

Navigating the Data Center Networking Landscape

System administrators today are tasked with creating a much smarter networking layer. One that is capable of keeping up with some of the most advanced business and IT demands. In a recent Worldwide Enterprise Networking Report, IDC pointed out that virtualization continues to have a sizable impact on the enterprise network. IDC expects that these factors will place unprecedented demands on the scalability, programmability, agility, analytics capabilities, and management capabilities of enterprise networks. They predict that in 2016, overall enterprise network revenue will grow 3.5 percent to reach $41.1 billion.

In one of my recent articles here on DCK, we defined the overall SDN landscape. We examined technologies like NSX, ACI, and even open SDN systems. Today, we take a step back and will look at four data center networking components impacting the modern business:

  • Traditional data center networking.
  • Software-defined networking.
  • White/brite box networking.
  • Cloud networking.

Read more at Data Center Knowledge

Reasons Organizations Opt Not to Use Open Source Software

Black Duck’s latest open source survey shows that a majority of companies are now using open source. So what’s stopping the rest? Here’s a look at the reasons why businesses might choose not to use open source, or avoid partnering with companies that do.

The fact that open source doesn’t work for everyone — or that some people think it won’t work for them, so they don’t even give it a try — does not mean open source is inherently flawed. It’s certainly a highly effective way to build and acquire software in many situations. Still, to understand open source fully, it’s worth taking a look at its drawbacks, both perceived and actual. They include…

Read more at The VAR Guy

NodeSource offers ‘One-Click’ Deployment of Node.JS for Kubernetes Clusters

NodeSource has configured a version of its N|Solid commercial Node.js implementation to run on Kubernetes clusters, potentially speeding both the deployments of containerized Node.js applications and N|Solid deployments themselves.

“We are seeing a ton of traction behind containers being orchestrated by Kubernetes,” said Joe McCann, CEO and co-founder of NodeSource. “For us, it makes sense to specialize an offering with N|Solid inside a Docker container orchestrated by Kubernetes.” 

Using Node.js in conjunction with containers can offer speedy deployment times, elaborated Ross Kukulinski, NodeSource technical product manager. About 45 percent of developers using Node.js are already using them with container technologies such as Docker.

Read more at The New Stack

Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode

Similarly to the previous tip about find out top processes by RAM and CPU usage, you can also use top command to view the same information. Perhaps there’s an extra advantage of this approach when compared to the previous one: the “header” of top provides extra information about the current status and usage of the system: the uptime, load average, and total number of processes, to name a few examples.

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]