Test your Shell Scripting Skills: – Program 5

scmuser created the topic: Test your Shell Scripting Skills: – Program 5

Write a script that behaves both in interactive and noninteractive mode. When no arguments are supplied, it picks up each C program from the current directory and lists the first 10 lines. it then prompts for deletion of the file. if the user supplies arguments with the script, then it works on those files only.

rajeshkumar replied the topic: Re: Test your Shell Scripting Skills: – Program 5

Following script should work….

#!/bin/sh
counter=0
if [ $# -eq 0 ]
then

for file in `find . -name "*.c"`
do
head -10 $file
counter=`expr $counter + 1`
echo "Do you want to delete this file=(Please type Y or N)"
read vote
case $vote in
Y|y) rm -f $file;;
n|N) exit ;;
*) echo "Invalid response"
esac
done
else

head -10 $1
echo "Do you want to delete this file=(Please type Y or N)"
read vote
case $vote in
Y|y) rm -f $1;;
n|N) exit ;;
*) echo "Invalid response"
esac
fi

echo "Number of files found=$counter"

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: Test your Shell Scripting Skills: – Program 5

#!/bin/sh
counter=0
if [ $# -eq 0 ]
then

for file in `find . -name "*.c"`
do
head -10 $file
counter=`expr $counter + 1`
echo "Do you want to delete this file=(Please type Y or N)"
read vote
case $vote in
Y|y) rm -f $file;;
n|N) exit ;;
*) echo "Invalid response"
esac
done
else

head -10 $1
echo "Do you want to delete this file=(Please type Y or N)"
read vote
case $vote in
Y|y) rm -f $1;;
n|N) exit ;;
*) echo "Invalid response"
esac
fi

echo "Number of files found=$counter"

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Test your Shell Scripting Skills: – Program 6

scmuser created the topic: Test your Shell Scripting Skills: – Program 6
Display a process in the system every 30 seconds five times using a(i) while loop (ii) for loop. What is the unusual feature of the for loop?

rajeshkumar replied the topic: Re: Test your Shell Scripting Skills: – Program 6

This should work….

#!/bin/bash
counter=0

while [ $counter -lt 5 ]
do

echo "Displaying running System process"
ps
echo "Displaying System Process and Top CPU using processes"
top
echo "Displaying One line Summary of System Status"
uptime

sleep 30
done

for counter1 in 1 2 3 4 5
do
echo "Displaying running System process"
ps
echo "Displaying System Process and Top CPU using processes"
top
echo "Displaying One line Summary of System Status"
uptime

sleep 30

done

The unusual feature of for loop is – There is no three part structure as used in C, Awk and perl. Unlike while and until, for does not test a condition, but uses a list instead.

for example…

for varibale in list
do
commands
done
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Complete Linux & Shell Scripting Guide and Tutorial for Linux Admin and DevOps Engineer

linux-shell-scripting-guide-and-tutorial

Linux User Commands

Linux Admin Commands

Useful Tools in Linux

Linux Shell Scripting Collection and Interview Guide

Linux Troubleshooting Guide

Linux Quiz

Linux Exercise

Linux Bash Scripting Video Tutorial and CBT

Tagged : / / / / / / / / / / / / / / /

Shell Scripting (Bash) Training | Bash/Shell Scripting Course

shell-bash-scripting-training

Introduction

  • Introduction
  • Why Shell Scripting?
  • Linux Internal
  • What to Expect From This Course?
  • Prerequisites

Git fundamental

  • Introduction of git
  • Git setup
  • Basic operations in git
  • Github
  • Summary

A First Look At Shell Scripts

  • Introduction
  • Creating A Shell Script
  • Demo: A Note-Taking Script
  • Calling The Script
  • The Shebang
  • Naming Your Script
  • Demo: The type Command
  • Summary

Variables

  • Introduction
  • Demo: Variables
  • Using Variables in A Script
  • Using Variables: Good Habits
  • Reading Input
  • Debugging your Script
  • Summary

If, Then, Else

  • Introduction
  • Demo: The If Statement
  • The If Statement
  • Return codes
  • The Conditional Expression
  • Demo: The Conditional Expression
  • The Conditional Expression 2
  • Arithmetic Tests
  • Demo: Arithmetic Tests
  • The If Statement Revisited
  • And, Or, Not
  • Summary

Input and Output

  • Introduction
  • Output: echo and printf
  • Input: read revisited
  • Standard Streams and Redirection
  • Demo: Redirection
  • Summary

Control Flow

  • Introduction
  • While and Until
  • The Classic For Statement
  • The C-Style For Statement
  • Break and Continue
  • The Case Statement
  • && and ||
  • Summary

Variables 2

  • Introduction
  • Integer Variables
  • Arithmetic Expressions
  • Arithmetic Expressions 2
  • Read-only Variables
  • Exporting Variables
  • Arrays
  • Summary

Handling Script Parameters

  • Introduction
  • Special Variables
  • Shift
  • Getopts
  • Getopts: Handling Errors
  • Summary

Shell Functions

  • Introduction
  • Shell Functions
  • Shell Functions 2
  • Functions: Demo
  • Some Miscellaneous Remarks
  • Summary

Fun with Strings

  • Introduction
  • Removing Part Of A String
  • Search and Replace
  • Setting A Default Value
  • Conditional Expression Patterns
  • Regular Expressions in The Conditional Expression
  • End of Options
  • Summary

Many Ways to Run Your Script

  • Introduction
  • Running your Code
  • Nohup and The Background
  • Exec
  • At and Cron
  • Set and Shopt
  • Summary
Tagged : / / / / / / / / / / / / / / / / / / / / / / / / /

Perl Scripting Interview – Selected Questions

perl-scripting-interview-selected-questions

Can anyone help on these questions which i couldnt answer in my interview,because iam not sure on perl scripting iam learning the things in perl now.

1.What standard Perl modules have you made use of, and why did you use them instead of the equivalent built-in functions?

2.Write a statement that checks to make sure there are at least two command line arguments and exits with an error if not.

3.How do you find the number of elements in an array?

4.Write a regular expression that would match only the last director of a full path filename (and you don’t know the path ahead of time).  Example: for “/fee/fi/fo/fum.txt” you would match “fo” with your regular expression

5.Write a Perl script to get the machine host name and print it. No system command should be used; this script should work on Windows and Linux OS without any change.
6.Write a Perl script to check a directory exists or not and print proper message. The directory location will be passed as parameter while executing the script.

Please help me out for the above questions.

Tagged : / / / / / / / / /

Ant Script with Shell script, How to run shell script from Ant Script?

ant-script-with-shell-script

Ant Script with Shell script
How to set files Permission in Ant | How to set files Permission in Unix | Set files Permission in Ant in Unix Environment
Command:
 

 

Ant Script to Replace some character in any files
 

 

How to run shell script using ant/
 
To Remove Some Special Character from Files
for name in `find PWD -type f`
do
if [ -f $name ]; then
tr -d “\015” ${name}XXXYYYZZZ
mv ${name}XXXYYYZZZ $name
echo “$name updated”
fi
done

 

Tagged : / / / / / / / / / / /