If you have a string "one two three", which shell command would you use to extract the strings?
Try this:
echo "one two three" | xargs
the output is: one two three
What are the different security mechanisms available in UNIX?
a) vi /etc/default/login
comment the line of /dev/console
b)vi .rhosts
enter the hostname by which the only user can connect with your system....bt no one else.....
c) disable the ftp for the selected users in /etc/ftpusers file ...
Unix is having 3 ways of Security Mechanism:1. By granting or revoking File permissions. Owner or Admin can change permissions to be given to group or others by using chmod command in Unix.2. Login is...
In shell scripting how to indentify that the previous command was run successfully?
in 2 ways it can be done:
1st way
$ echo $?
2nd way:
$ pwd 2> error| cat error|wc -l
0
$ cat h 2> error| cat error|wc -l
1
pwd or cat or any command if outpt is 0 then successful else failed.
Shell script to track file changes
Write a shell script to save the output of 'ls -ltr' every five minutes and after every hour it should print which all files are changed/modified/created.
find $HOME -mmin -5 -ls # run the same in cron
find . -mtime 0 # find files modified between now and 1 day ago (i.e., within the past 24 hours)find . -mtime -1 # find files modified less than 1 day ago (i.e., within the past...
Write a shell script to join two csv text files based on value of some columns?
How to compare floating point number in shell scripting ?
What is the difference between a shell variable that is exported and the one that is not exported?
global variable is created using export command in ksh - export x='name' In csh its created using setenv command-setenv x 'name'this 'x' variable will be visible in curren...
try this simple script it will clear your concept :-
script a.sh :-
----------
export A=3
B=5
sh b.sh
--------
script b.sh :-
-----------
echo "exported variable $A is :- $A"
echo "Variable $B -- $B "
---------
A persists in b.sh whereas B doesn't.
K Shell,
Bourne Shell,
Bash,
C-Shell
ashell
bshell
bash (born again shell)
cshell
kshell
zshell
Contains the list of arguments passed to the function.
It contains the actual arguments passed to a shell script
How do you schedule a command to run at 4:00 every morning?
1st step$ cat > cmdfile//<Minute> <Hour> <Day Of Month> <Day Of Week> <Command> 0 &n...
How connect to a database in shell programming?Please tell me step by step?
$ORACLE_HOME/bin/sqlplus username/password@remote_db
IF the Database is DB2 then the script is :
You have current directory containing set of directories which contain files.One file can reside in many directories.Write script which returns number of unique file names inall the subdirectories of a current dir.
Write a shell script to identify the given string is palindrome or not?
read string1
string_rev=`rev string1`
if [ string1 = string_rev ]
then
echo palindrome
else
echo not a palindrome
fi
echo enter a string read stringlen=`expr length "$string"`i=$lenreverse=''while [ $i -gt 0 ]dochar=`echo $string | cut -c $i`reverse="$reverse$char"i=`expr $i - 1`doneecho ...
What is this line in the shell script do ?#!/bin/ksh?
#! at the start of the file indicates that this is a shell script file, rather than a normal file./bin/ksh -- runs the shell script in ksh shell.By default the shell script runs in the current shell (...
#! line states the interpreter to be used by the shell to interpret the script.
Here, ksh interpreter is invoked for interpretation of the script.
What are the different kinds of lOOPS available in shell script?
While loopThe syntax for while is: while conditiondo statements...done For loopsThe syntax for the for loop: for name [in list]do statements that can use $name...done Untill loopsThe ...
3 loops
for
while
until --> Just reverse of while loop
-----------------------
"if-elif" or "if else" or "case" not comes in the loop
What are the steps to take files from UNIX server to windows?
Most UNIX servers are configured not to use FTP or TELNET for security purposes, and if you use FTP it has limited number of data can be transfered on one transaction hence I preferred using another w...
If you can't get Samba, or you're not the Admin so you can't install it anyway, then use FTP, as it's almost guaranteed to be installed and running on both machines. The only han...
What does uid and gid signify?
To find a user's UID or GID in Unix, use the id command. To find a specific user's UID, at the Unix prompt, enter: id -u username Replace username with the appropriate user's username. To find ...
UID - User idGID - Group idWe can find out using sample command fire @ $ promoit "id" you will user id & group id.e. g step 1 : $ id ---> O/p get display immediately uid=232(vi...
dos2unix only removes the control-M characters at the end of the line. You need to use sed to do the search and replace for '' to '/'.
Command to list all the differences between two dir:
diff -r
Diff.txt will show you all the differences.
How to compare two floating point numbers ?
How to perform the arithmetic operations on floating point numbers ?
We can use test also in command line
test 1.2 -gt 1.1 | echo "abhishek"
You will get o/p
abhishek.
You can make you og 'bc' command to do the arithmatic operations in shell script.
Following script illustrates a sample implimentation
a=1.2
b=3.1
x=$(echo $a+$b|bc)
echo [$x]
Where the arithmatic operation that is desired is marked in bold.
Using KSH while loop#!/bin/ksh
#Get the count of total number of arguments passed while executing this script
int i = $#; #total number of arguments passed#
names=$@; #list of actual arguments passed#
while [ ${i} -gt 0 ]
do
echo '${names[i]}';
i=`expr i - 1`;
done
exit 0;
$ cat rev2
i=$#
echo "$@" > file_1
while [ $i -gt 0 ]
do
cut -f $i -d" " file_1 >> file_2
i=`echo $i-1|bc`
done
echo `cat file_2`;
rm -f file_1 file_2;
$ sh rev2 A B C D E
E D C B A