Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i know what bash is...and i know what scripting is
but where is bash scripting used mostly...i mean can somebody give me a real world example
of how bash scripting is used in day to day working environments
and is there good work placement for a guy who knows bash scripting well...
but where is bash scripting used mostly...i mean can somebody give me a real world example
of how bash scripting is used in day to day working environments
Bash scripts (and one-liners) are used all over the place:
and is there good work placement for a guy who knows bash scripting well...
Knowing bash (scripting) is just one tool that is good to have. If bash scripting is the only thing you are good at then the chances of getting work will not increase.
-When users log in a few files are executed, e.g. .bashrc, .bash-profile etc
-Cronjobs
-Loads of (semi-)automated tasks, e.g. backups
-Things you need to do more than once
-system handling, e.g. ifup/ifdown etc.
-service/deamon handling, e.g. /etc/init.d files
Sysadmins (like myself) have built scripts to automate tasks and make things more user-friendly.
At a previous posting, I designed a backup solution that used rman, gpg, and tar to write to an attached tape drive. Rather than teaching the rest of the staff who would be running the backups (as most of them didn't have the UNIX skills I do), I wrote a shell wrapper for it that would run the tasks and present them with output so they were aware of what was going on.
i know what bash is...and i know what scripting is
but where is bash scripting used mostly...i mean can somebody give me a real world example
of how bash scripting is used in day to day working environments
and is there good work placement for a guy who knows bash scripting well...
Bashing is for automation mainly. You make a bash script for anything you end up doing constantly. Like backups.
My rule as a Network admin is, if I do it manually more than once, I will script it so I can do it in less time, but pretend it toook the same amount of time and go to the bar.
but where is bash scripting used mostly...i mean can somebody give me a real world example of how bash scripting is used in day to day working environments
I often use it for bulk file manipulation. Here's an example:
Code:
for File in $(ls)
do
Name=$(expr $File : '\(.*\)\.wav')
sox $File $Name.cdr
done
This processes a bunch of *.wav files in a directory into *.cdr files in preparation for CD burning with cdrecord. I just type the code in at the command prompt, but it could just as easily be made into an actual BASH script. Just add the line:
"#!/bin/bash" as the first line, and
"exit 0" as the last line and you're good to go. Just don't forget to make it an executable (or start it with: "/bin/bash MyScript.sh")
Here are a couple more examples:
Code:
# Define a couple of macros to help end users
# determine if they need to install the FOX libs.
#
# Try to compile a very simple FOX app that calls
# the default constructor of the FXApp object, and
# immediately throws it away. If this object can't be
# called, a FOX app can't run.
AC_DEFUN([SIMO_FOX_COMPILE],
[# FOX Version: 1.6
ac_fox_compile="$CXX -g -c FoxTest.cpp"
cat > FoxTest.cpp << EOF
#include <fox-1.6/fx.h>
int main(void)
{
FXApp();
return 0;
}
EOF
# Compile test: must have FOX headers for this. Use system path
# to FOX header files.
if { (eval echo "$as_me:$LINENO: \"$FoxCompile\"") >&5
(eval "$ac_fox_compile") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(eval echo "$as_me:$LINENO: Run FoxTest") >&5
(exit $ac_status); }
then
AC_MSG_RESULT([====> Compile test successful <====])
else
rm -f FoxTest.cpp
cat << EOF
!!!!!!!!!!!!!!!! Configure Error !!!!!!!!!!!!!!!!!!!!!!
!! !!
!! FOX libs not found on this system !!
!! Please install FOX from the included "tarball" !!
!! Then re-run configure. (See "INSTALL" for more !!
!! details.) !!
!! !!
!!!!!!!!!!!!!!!! Configure Error !!!!!!!!!!!!!!!!!!!!!!
EOF
exit 1
fi])
AC_DEFUN is an autoconf macro that allows you to write your own m4, autoconf compatible, macros that can be dropped right into a configure.ac file. Autoconf takes that file, and working with automake, creates your configure script. When it sees "SIMO_FOX_COMPILE", it drops that bash code into the script.
Another one:
Code:
# Macro to link and run a very simplistic FOX app.
# If this test fails, it means that either the FOX
# shared libs are corrupt, missing, or most likely
# ld can't find them because they're either in some
# wierd location, or weren't registered with ld.
#
# After installing FOX, run /sbin/ldconfig to register
# the new libs. (Some distros (Slackware) do this on
# reboot, others do not.) If this test succeeds, you're
# good to go!
AC_DEFUN([SIMO_FOX_RUN],
[ac_fox_link="$CXX -lFOX-1.6 -o FoxTest FoxTest.o"
rm -f FoxTest.cpp
if { (eval echo "$as_me:$LINENO: \"$FoxLink\"") >&5
(eval "$ac_fox_link") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(./FoxTest) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }
then
AC_MSG_RESULT([====> Linked and ran test program successfully <====])
FoxLibs="-lFOX-1.6"
else
cat << EOF
!!!!!!!!!!!!!!!! Configure Error !!!!!!!!!!!!!!!!!!!!!!
!! !!
!! Link test failed. FOX libs are present, however, !!
!! they were likely not registered with ld after !!
!! doing the install. See the file INSTALL for !!
!! details on installing FOX and registering these !!
!! libs so that ld can find them without specifying !!
!! a path to the FOX libs. (Essential in order to !!
!! easily launch the app!) !!
!! !!
!!!!!!!!!!!!!!!! Configure Error !!!!!!!!!!!!!!!!!!!!!!
EOF
rm -f FoxTest.o
exit 1
fi
rm -f FoxTest.o
rm -f FoxTest
AC_SUBST(FoxLibs)])
This one tries to actually run the simple program. If it succeeds, then it knows the FOX libs are there and linkable. The makefile variable "FoxLibs" is set in the makefiles. It does the clean-up, and lets the configure process complete to generate the required makefiles that compile the app and install it.
If it blows up, configure exits on an error.
You can define all sorts of custom tests for configure with a bit of BASH scripting, distribute the custom macros in a directory usually called "m4" in the distribution. You can call it whatever you like, but "m4" is a directory that aclocal looks for automatically when it finds nonstandard macros, so you don't need an extra command line switch to make it look in odd locations for undefined macros.
Quote:
and is there good work placement for a guy who knows bash scripting well...
Can't hurt if you do know it. Another thing BASH scripting is good for is quick prototyping of routines that will make their way into compiled apps, as you know right away where a script blows up, and all you need to do is edit it and run. No waiting for anything to compile to see if you've caught all the bugs.
These are the 3 scripts I use the most. I some times get 50 or so pictures from club mmembers about fishing trip.
I can produce an 'html' file to put on the web site in about 15 minutes or less.
Rename the image incase of camera duplicates.
Code:
#! /bin/bash
# check if there is no command line argument
if [ $# -eq 0 ]
then
echo "You forgot the image name to be used!"
echo "Usage :: new image name"
exit
fi
new_image_name=$1_`date +"%F_%k"`
counter=1
for i in *.jpg *.JPG *.png *.gif *.jpeg; do echo "$i"; cp "$i" "$counter"_"$new_image_name".jpg; echo "$counter"_"$new_image_name" echo $counter; let "counter += 1"; done
Resize the images.
Code:
#! /bin/bash
for i in *.jpg *.JPG *.png *.gif *.jpeg; do echo "$i"; convert -size 256x "$i" -resize 256x "$i"; done
Build a table to copy past into an 'html' header.
Code:
#!/bin/bash
target=html`date +"%F_%k"` ##file name
bodyheader="
<body bgcolor=\"#efb321\" text=\"#f8c99f\" link=\"#006666\" vlink=\"#003300\">"
echo "$bodyheader" >> "$target"
headerline="
<p align=\"center\" style=\"line-height: 100%; margin-top: 0; margin-bottom: 0\"> </p>
<table border=\"1\" width=\"90%\" bordercolor=\"#f8c99f\" bordercolorlight=\"#efb321\" bordercolordark=\"#f8c99f\" bgcolor=\"#a95205\" id=\"table1\">"
echo "$headerline" >> "$target"
for filename in *.gif *.jpg *.JPG *.png *.jpeg; ##list all images in directory
do
if [ -f "$filename" ]
then
### If I can get them to rename the file this will put a caption line under the pix
### otherwise it puts the camera generated name.
CAPTION=${filename%.*}
imageline="
<td align=\"center\"> <p style=\"margin-top: 0; margin-bottom: 0\"> <img border=\"0\" src=\"$filename\"></a></p> <!-- <p style=\"margin-top: 0; margin-bottom: 0\">"$CAPTION"</p> --> </td>"
echo "$imageline" >> "$target" ##write to disk.
else
:
fi
done
So there's already lot of example given to you for bash scripting how it is and as Druuna said it is just a tool and a added skill you have if you know it but that individually doesn't increase any chances of getting a good job.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.