tag:blogger.com,1999:blog-58262318622954917952024-03-19T01:46:04.998-07:00Linux Worldtuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.comBlogger542125tag:blogger.com,1999:blog-5826231862295491795.post-22082923183386061572023-10-15T01:53:00.000-07:002023-10-15T01:53:03.411-07:00Black screen in vsphere 7.x client on installing unbuntu<p>On booting an Installation of ubuntu on the vspehere 7.x client can sometimes show a black screen instead of the actual GUI of ubunutu. One the possible reasons for this could be a simple setting in the virtual machine. To check if its problem with vm setting try the following. <br /></p><div>Power off vm and go to edit settings-> virtual
hardware->video card and select option "auto detect settings" and
un-check box enable 3D support if checked.</div><div> </div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZH-cQWCd2S5SMfEWkocIb_Qndz14bfcPZMm0EPZxWHxNdnoQR6auyoj7wuE1iq_dxooqT6N-HGJ2j24vpnpTb2Bt8zMAN9EDZo2Ub7G6EMVO7lObbMSpIzJTOj7qT-Zs5HFT1jSMalvS4_2XsuH07wMPdnHuwiGFXf0Wn0LB0G40Zu7QnjfmYuopOcPw/s1749/ubuntu-blackscreen.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1637" data-original-width="1749" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZH-cQWCd2S5SMfEWkocIb_Qndz14bfcPZMm0EPZxWHxNdnoQR6auyoj7wuE1iq_dxooqT6N-HGJ2j24vpnpTb2Bt8zMAN9EDZo2Ub7G6EMVO7lObbMSpIzJTOj7qT-Zs5HFT1jSMalvS4_2XsuH07wMPdnHuwiGFXf0Wn0LB0G40Zu7QnjfmYuopOcPw/s320/ubuntu-blackscreen.png" width="320" /> </a></div><div style="text-align: center;"> </div><div style="text-align: left;">Once the setting is changed, power on the virtual machine and you should be able to see the ubuntu gui. </div><div style="text-align: left;"> </div><div style="text-align: left;"> <br /></div><p></p>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-77579483245732693282022-08-23T04:31:00.000-07:002022-08-23T04:31:12.366-07:00Resize Images Using GIMP
Here is quick look at the steps that can be followed to resize an Image using gimp.
Resize could be either to reduce the height and width or the memory size of the image. For example if you need the a image to be of only 40KB, and the current size is 100KB then you can resize the image to a smaller height and width and reduce the memory size of the image . <br />
<br /> <br /> <br /> <br /> <br />
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOr5xuipHdrlf4oxONi0oAFUdEEK-4sTToLh1GodFMgszjD4iOxV-iRRCmcD_yNY5qOvHrUs775BJUWekiW27H0hLGArk1iqjsdvGVMbNs1f7tRnpAC8ip61XZ7hMwC42eOYM6GA3SJoE_-p77QSwC_OlIHEUqRteSU3Sbz3ZVcjT48LlgTScPvpBn/s1366/gimp_open.gif" style="display: block; padding: 1em 0px; text-align: center;"><img alt="" border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOr5xuipHdrlf4oxONi0oAFUdEEK-4sTToLh1GodFMgszjD4iOxV-iRRCmcD_yNY5qOvHrUs775BJUWekiW27H0hLGArk1iqjsdvGVMbNs1f7tRnpAC8ip61XZ7hMwC42eOYM6GA3SJoE_-p77QSwC_OlIHEUqRteSU3Sbz3ZVcjT48LlgTScPvpBn/w640-h360/gimp_open.gif" width="640" /></a></div>
<br /> <br /> <br /> <br /> <br />
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-51785205372954596442022-07-20T04:20:00.003-07:002022-07-20T04:22:37.952-07:00vmware vmplayer unable to install all modules ubuntu<br/>
While installing the vmplayer 16.1.2 in ubuntu 20.04 the installation failed with the error message
<br/> <br/>
<textarea cols="80" name="Name" rows="2">
unable to install all modules ubuntu
</textarea>
<br/> <br/>
The logs indicated that the issue with the installation of the module vmmon. One of the workaround that worked was to
download the source file from
<textarea cols="80" name="Name" rows="2">
https://github.com/mkubecek/vmware-host-modules/tree/workstation-16.1.2
</textarea>
<br/> <br/>
After downloading, unzip the files and go to the folder vmmon-only/include . Open the file vm_asm_x86.h and comment out a part of the code a shown in the figure below.
<br/> <br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmhzguKp3-XPkGsnUgDsSbmyvyIrBa-r0uQff8CQhIa0a1BQLhBQCFFIB_dB1GMPs6-tDYPCW8LVjnsO0jdS6Q_PkYJ8YS35ZmWBOZrpzLUj9fqT45olZkS6rygT0sYqg3Zz5X-Ac-4NUlluxcjRmgaZA12NCQXiD9xjSeK72OWESHDDrAZo-dJccm/s1181/Screenshot%20from%202022-07-20%2016-40-34.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="528" data-original-width="1181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmhzguKp3-XPkGsnUgDsSbmyvyIrBa-r0uQff8CQhIa0a1BQLhBQCFFIB_dB1GMPs6-tDYPCW8LVjnsO0jdS6Q_PkYJ8YS35ZmWBOZrpzLUj9fqT45olZkS6rygT0sYqg3Zz5X-Ac-4NUlluxcjRmgaZA12NCQXiD9xjSeK72OWESHDDrAZo-dJccm/s320/Screenshot%20from%202022-07-20%2016-40-34.png"/></a></div>
<br/> <br/>
Now rebuild the new modules and install using the follwing set of commands, running them inside the new folder that was downloaded from the above link.
<br/> <br/>
<textarea cols="80" name="Name" rows="4">
tar -cf vmmon.tar vmmon-only
tar -cf vmnet.tar vmnet-only
sudo cp -v vmmon.tar vmnet.tar /usr/lib/vmware/modules/source/
sudo vmware-modconfig --console --install-all
</textarea>
<br/> <br/>
Now launch the vmplayer, it should open with out any errors. Please note that the solution has been verified on the specific version mentioned so it might or might not work on all versions.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-53149558328853977752022-07-19T21:55:00.000-07:002022-07-19T21:55:06.691-07:00Linux bash script to find Average of prime numbers in rangeThis post in reponse to a comment on the post "<a href="https://tuxthink.blogspot.com/2012/12/linux-script-to-find-prime-numbers-in.html?showComment=1657008665609#c5833076549617439599" target="_blank"> Linux script to find prime numbers in a range of numbers</a> "
The request was to find the average of all the prime numbers found in the given range.
<br />
<br />
<textarea cols="80" name="Name" rows="30"> #! /bin/bash
low=1
count=0
sum=0
while [ $low -eq 1 ]
do
echo "Enter the lower limit,greater than 1"
read low
done
echo "Enter the upper limit"
read upper
for mun in `seq $low $upper`
do
ret=$(factor $mun | grep $mun | cut -d ":" -f 2 | cut -d " " -f 2)
if [ "$ret" -eq "$mun" ]
then
echo "$mun is prime"
((count++))
sum=$((sum+mun))
fi
done
average=$((sum/count))
echo -e "\n There are $count number of prime numbers"
echo "The sum of the prime numbers is $sum"
echo "The average of the prime numbers is $average"
</textarea>
<br/>
<br/>
Save the file say as average_prime_range.sh Execute it using bash.
<br/>
<br/>
<textarea cols="80" name="Name" rows="2">
$bash average_prime_range.sh
</textarea>
<br/>
<br/>
Following is a sample output
<br/>
<br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEchvW5F8NtVT7UYeeSm59JbgKHJJYZoN23-mj287zYXPBqZ6tUd3rSd0zLM_hkneWe-7I0F4OCUdry8_1JUEIFJYrTABkqOfCqEamN7dCnw8hD1nzKpX4fgF3c4cGeXmFOKRCaIrL-Ae1MHOyiowgSjhREmUJfloT4ENa4LZqKAnk0o4l3r6VSEUQ/s553/Screenshot%20from%202022-07-20%2010-21-53.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="309" data-original-width="553" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEchvW5F8NtVT7UYeeSm59JbgKHJJYZoN23-mj287zYXPBqZ6tUd3rSd0zLM_hkneWe-7I0F4OCUdry8_1JUEIFJYrTABkqOfCqEamN7dCnw8hD1nzKpX4fgF3c4cGeXmFOKRCaIrL-Ae1MHOyiowgSjhREmUJfloT4ENa4LZqKAnk0o4l3r6VSEUQ/s320/Screenshot%20from%202022-07-20%2010-21-53.png"/></a></div>
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-4102263159380127132022-04-24T06:06:00.001-07:002022-04-24T06:06:35.948-07:00Sending mails from the command line to multiple receipents using gnome-gmail. Here is a script which can be used to send a common mail to all number of receipients, with all the recepient mail ids stored in a text file.
<br /><br />
The script uses the tool gnome-gmail, which can be installed from your package repository, In debian based systems it can be installed using
<br /><br />
<textarea cols="80" name="Name" rows="2">
apt-get install gnome-gmail.
</textarea>
<br /><br />
Create a file called mialIds which will have a a list of mail ids to which mails need to be sent. For example
<br /><br />
<textarea cols="80" name="Name" rows="4">abc@gmail.com
xyz@gmail.com
abcd@gmail.com
xwv@gmail.com</textarea>
<br /><br />
Create a file with the following script and name it as mailscript.sh
<br /><br />
<textarea cols="80" name="Name" rows="10">#!/bin/bash
input="mailIds"
subj="Hello"
bod="Have a nice day"
while IFS= read -r line
do
echo "$line"
gnome-gmail -s "mailto:$line?&subject=$subj&body=$bod"
done < "$input" </textarea>
<br /><br />
The input variable in the script should point to the file containing the mail ids.. If the script and the file containing mail ids are in the same folder, then just the name is enough.
<br /><br />
The variable subj is used to store the content to be filled in the subject line of the mail. The variable bod will contain the text for the body of the email.
<br /><br />
Execute the script
<textarea cols="80" name="Name" rows="2">
$bash mailscript.sh
</textarea>
<br /><br />
If you execute it the first time, gnome-gmail will prompt you to enter the gmail id that needs to be use dfor sending the email. If the gmail is in the logged in state in the browser, it will be able to send the mail automatically, else it might open the login prompt for you to login into the gmail account.
Gnome-gmail Its a great way to automate sending default emails.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-40843768226815267422022-04-02T22:32:00.001-07:002022-04-03T00:50:48.766-07:00[: -eq: unary operator expected <br /><br />
<textarea cols="80" name="Name" rows="2">
[: -eq: unary operator expected
</textarea>
<br />
<br />
The above error might come when we are using conditional operators to compare two values in a bash script. For example , conisder the following script to compare a user input number with a constant.
<br />
<br />
<textarea cols="80" name="Name" rows="6">
read $input
if [ $input -eq 10 ]
then
echo "Equal"
fi
</textarea>
<br />
<br />
The above script when executed will throw the error as listed before. The error in the program is use of $ while taking the input, that is the right way of using the read command is "read <variable name> without a $ symbol before the name.
<br />
<br />
<textarea cols="80" name="Name" rows="6">
read input
if [ $input -eq 10 ]
then
echo "Equal"
fi
</textarea>
<br />
<br />
The second possible reason for the error could be not passing two values to compare for the operataor , for example the script below will also throw the same error as the operator "eq" has been given only a single operand.
<br />
<br />
<textarea cols="80" name="Name" rows="6">
read input
if [ $input -eq ]
then
echo "Equal"
fi
</textarea>
<br />
<br />
In the above example, we have missed passing the constant after the comparision opertaor.
<br />
<br />
Looking in the above two possibilities should fix the error.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com1tag:blogger.com,1999:blog-5826231862295491795.post-32971769994213885762022-03-21T03:17:00.003-07:002022-04-02T22:22:01.001-07:00Guess the number game in shell scriptExecute the following script to play "Guess the number" Game on the linux terminal. The computer picks a random number between 0 and 10 and the user has to guess the same, with in 3 attempts.
<br />
<br />
<textarea cols="80" name="Name" rows="34">#!/bin/bash
guess=$(($RANDOM %10))
attempts=3
for(( i=0;i<$attempts;i++ ))
do
echo "Guess a number between 0 and 10 ,including 0 and 10"
read input
if [ $input -lt $guess ]; then
echo "Too small"
elif [ $input -gt $guess ]; then
echo "Too big"
elif [ $input -eq $guess ]; then
echo "********************"
echo "Congratulations Correct guess"
echo "********************"
exit
fi
done
if [ $input != $guess ]
then
echo "********************"
echo "Sorry The correct number was $guess"
echo "********************"
fi
</textarea>
<br />
<br />
Save the file as "guessTheNumber.sh" and execute the script from the terminal.
<textarea cols="80" name="Name" rows="2"> $ bash <textarea name="Name" rows="34" cols="80">
</textarea>
<br />
<br />
The output would look as shown below. You can increase the number of attempts by changing the value of the attempts variable .
<br />
<br />
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjkTMFFeihvuTh3kGXTn-5xrm8Fo7vWKq5kGLOFPw_2oQknvIKQm1xEPetu5ERWkI54LgfktfxOonpkBRw7rP5jh-QetkeAL-WXk7QdTZ22io8mI5ZNWqflH4bRaYll4JbJ643uitAWiJ1NIyrGP0Mivp-J2vwjxVnUfaMgQVCbSYNUCJDl-XBCKXB3=s546" style="display: block; padding: 1em 0px; text-align: center;"><img alt="" border="0" data-original-height="211" data-original-width="546" height="155" src="https://blogger.googleusercontent.com/img/a/AVvXsEjkTMFFeihvuTh3kGXTn-5xrm8Fo7vWKq5kGLOFPw_2oQknvIKQm1xEPetu5ERWkI54LgfktfxOonpkBRw7rP5jh-QetkeAL-WXk7QdTZ22io8mI5ZNWqflH4bRaYll4JbJ643uitAWiJ1NIyrGP0Mivp-J2vwjxVnUfaMgQVCbSYNUCJDl-XBCKXB3=w400-h155" width="400" /></a></div>
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-71522845782405950532021-12-30T21:21:00.000-08:002021-12-30T21:21:15.921-08:00Script to create 2022 on linux terminal with a mask on the 0. Here is a script you can run on the linux terminal to generate 2022 on the terminal using any charachter you want. With the charachter 0 covered partiall to indicate the need for mask in the new year too.
<br/>
<br/>
<textarea name="Name" rows="244" cols="80">
#!/bin/bash
#create 2022 on terminal using any user specified character
str_dwn() {
rows=$1
s_start=$2
char=$4
str_st_row=$3
rows_end=$((str_st_row+rows))
for((i=str_st_row;i<rows_end;i++))
do
tput cup $i $s_start
printf "$char "
done
echo""
}
backslash() {
b_st_row=$1
b_st_cols=$2
b_char=$3
b_r_end=$((b_st_row + 5 ))
for((p=b_st_row;p<b_r_end;p++))
do
tput setaf $4
tput cup $p $b_st_cols
printf "$b_char "
((b_st_cols++))
done
echo""
}
forward() {
f_st_row=$1
f_st_cols=$2
f_len=$3
f_char=$4
f_r_end=$((f_st_row + $f_len))
for((i=f_st_row;i<f_r_end;i++))
do
tput cup $i $f_st_cols
printf "$f_char "
((f_st_cols--))
done
echo""
}
horizontal() {
hrow=$2
hstart=$1
hcols=$3
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
half_horizontal() {
hrow=$2
hstart=$1
hcols=$(($3/2))
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
gen_rand() {
num1=$1
if [ $num1 -eq 0 ]
then
temp=$(($RANDOM % 2))
rand=$((temp + 2))
else
temp=$(($RANDOM % 5))
rand=$((temp + num1))
fi
}
two() {
hstart_2=$1
hrow_be=$2
hcols_2=$3
char=$4
color=$5
set_color
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
hstart_2_lo=$start
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
zero() {
set_color
hstart_0=$((f_st_cols_2 +4))
hcols_0=5
horizontal $hstart_0 $hrow_be $hcols_0 "$char"
str_dwn_col_0=$hstart_0
str_dwn_row_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_0 $str_dwn_row_0 "$char"
hstart_0_lo=$((f_st_cols_2 +4))
hcols_0_lo=6
hrow_0_lo=$((hrow_be+4))
horizontal $hstart_0 $hrow_0_lo $hcols_0 "$char"
hrow_0_lo=$((hrow_be+5))
horizontal $hstart_0 $hrow_0_lo $hcols_0 "$char"
hrow_0_lo=$((hrow_be+6))
horizontal $hstart_0 $hrow_0_lo $hcols_0 "$char"
str_dwn_col_rig_0=$((hstart_0 +5))
str_dwn_row_rig_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_rig_0 $str_dwn_row_rig_0 "$char"
}
twoo() {
set_color
set_color
##############################
hstart_2=$((str_dwn_col_rig_0 +2))
hcols_2=6
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
###############################################
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
######################################################
hstart_2_lo=$hstart_2
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
twooo() {
set_color
set_color
##############################
hstart_2=$((str_dwn_col_rig_0 +10))
hcols_2=6
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
###############################################
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
######################################################
hstart_2_lo=$hstart_2
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
set_color(){
color=$RANDOM
color=$((color%6))
tput setaf $color
}
cols=`tput cols`
mid=$((cols/2))
start=$((mid-16))
#char="="
echo "What character do you want to use"
read char
tput clear
rows=5
begin_row=2
num_cols=6
two $start $begin_row $num_cols "$char" $color;zero;twoo;twooo
tput setaf 7
tput cup 9 0
</textarea>
</br>
</br>
save the above script say as 2022.sh and execute it on the terminal using
<textarea name="Name" rows="2" cols="80">
$ bash 2022.sh
What character do you want to use
</textarea>
</br>
</br>
2022 should appear on the terminal in random colors as shown in the figure below. Note the partial shading of the charachter 0 to indicate the mask.
</br>
</br>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgKM-FZ4ETzsEcAGNu55RseNu7WN-GpIRXKN6xKIGIy4C74WxywVV9fq6Ov5Dbmn7hWbG9LthHTDdvputhJs2HO6RU0jI_wLtjxZYPmMU2knnGzcyZKXxSl0a-OZ-emt5tXIB36b-Y4LtVWO48RE812XxOCh4Ac7Gg73dWnSW4BAwOAqnRkoTFlSIEW=s353" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="159" data-original-width="353" src="https://blogger.googleusercontent.com/img/a/AVvXsEgKM-FZ4ETzsEcAGNu55RseNu7WN-GpIRXKN6xKIGIy4C74WxywVV9fq6Ov5Dbmn7hWbG9LthHTDdvputhJs2HO6RU0jI_wLtjxZYPmMU2knnGzcyZKXxSl0a-OZ-emt5tXIB36b-Y4LtVWO48RE812XxOCh4Ac7Gg73dWnSW4BAwOAqnRkoTFlSIEW=s320"/></a></div>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-6922754616663669622021-12-30T21:16:00.000-08:002021-12-30T21:16:07.006-08:00Script to create 2022 On Linux Terminal Here is a script you can run on the linux terminal to generate 2022 on the terminal using any charachter you want.
<br/>
<br/>
<textarea name="Name" rows="230" cols="80">
#!/bin/bash
#create 2022 on terminal using any user specified character
str_dwn() {
rows=$1
s_start=$2
char=$4
str_st_row=$3
rows_end=$((str_st_row+rows))
for((i=str_st_row;i<rows_end;i++))
do
tput cup $i $s_start
printf "$char "
done
echo""
}
backslash() {
b_st_row=$1
b_st_cols=$2
b_char=$3
b_r_end=$((b_st_row + 5 ))
for((p=b_st_row;p<b_r_end;p++))
do
tput setaf $4
tput cup $p $b_st_cols
printf "$b_char "
((b_st_cols++))
done
echo""
}
forward() {
f_st_row=$1
f_st_cols=$2
f_len=$3
f_char=$4
f_r_end=$((f_st_row + $f_len))
for((i=f_st_row;i<f_r_end;i++))
do
tput cup $i $f_st_cols
printf "$f_char "
((f_st_cols--))
done
echo""
}
horizontal() {
hrow=$2
hstart=$1
hcols=$3
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
half_horizontal() {
hrow=$2
hstart=$1
hcols=$(($3/2))
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
gen_rand() {
num1=$1
if [ $num1 -eq 0 ]
then
temp=$(($RANDOM % 2))
rand=$((temp + 2))
else
temp=$(($RANDOM % 5))
rand=$((temp + num1))
fi
}
two() {
hstart_2=$1
hrow_be=$2
hcols_2=$3
char=$4
color=$5
set_color
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
hstart_2_lo=$start
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
zero() {
set_color
hstart_0=$((f_st_cols_2 +4))
hcols_0=5
horizontal $hstart_0 $hrow_be $hcols_0 "$char"
str_dwn_col_0=$hstart_0
str_dwn_row_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_0 $str_dwn_row_0 "$char"
hrow_0_lo=$((hrow_be+6))
horizontal $hstart_0 $hrow_0_lo $hcols_0 "$char"
str_dwn_col_rig_0=$((hstart_0 +5))
str_dwn_row_rig_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_rig_0 $str_dwn_row_rig_0 "$char"
}
twoo() {
set_color
set_color
##############################
hstart_2=$((str_dwn_col_rig_0 +2))
hcols_2=6
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
###############################################
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
######################################################
hstart_2_lo=$hstart_2
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
twooo() {
set_color
set_color
##############################
hstart_2=$((str_dwn_col_rig_0 +10))
hcols_2=6
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
###############################################
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
######################################################
hstart_2_lo=$hstart_2
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
set_color(){
color=$RANDOM
color=$((color%6))
tput setaf $color
}
cols=`tput cols`
mid=$((cols/2))
start=$((mid-16))
echo "What character do you want to use"
read char
tput clear
rows=5
begin_row=2
num_cols=6
two $start $begin_row $num_cols "$char" $color;zero;twoo;twooo
tput setaf 7
tput cup 9 0
</textarea>
</br>
</br>
save the above script say as 2022.sh and execute it on the terminal using
<textarea name="Name" rows="2" cols="80">
$ bash 2022.sh
What character do you want to use
</textarea>
</br>
</br>
2022 should appear on the terminal in random colors as shown in the figure below.
</br>
</br>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgfqPZZCBRQUfm2HcTv_urHZ-dEdW3rGegNbWru_saR7-1oVgBfmF0sJCz110oH4MyejaBysxXAgaWWdF2bnAsSHmOcpjzQnvQQanCL9Gjsct8haHut08yIQdFxvjiFu2rvOX-cg9ri42l4dzQyNGRX-QLowEvD3lddiWGczUZb6i9E8uUfH2XD0IVN=s362" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="164" data-original-width="362" src="https://blogger.googleusercontent.com/img/a/AVvXsEgfqPZZCBRQUfm2HcTv_urHZ-dEdW3rGegNbWru_saR7-1oVgBfmF0sJCz110oH4MyejaBysxXAgaWWdF2bnAsSHmOcpjzQnvQQanCL9Gjsct8haHut08yIQdFxvjiFu2rvOX-cg9ri42l4dzQyNGRX-QLowEvD3lddiWGczUZb6i9E8uUfH2XD0IVN=s320"/></a></div>
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-66776343312284319032021-10-18T20:05:00.000-07:002021-10-18T20:05:55.496-07:00div function in C to find the quotient and reminder While performin the division operation in a C program, we can get the reminted of division using the modulus operator. But getting quotient when the numbers are not completely divisble , for example if we divide 15 by 4, and want to find the quotient the usual divide operator will not be useful as it will give a floating point result.
We can use the div function for this which is a part of the stdlib library. The div function takes two arguments, first one being the divident, the second one being the divisor.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
result=div(divident,divisor)
</textarea>
<br/>
<br/>
The return value of the div fundtion is a structure of the form div_t, which has two member variables , Quotient and reminder.Thus to get the quotient and reminder we just ned to access these member variables in the return value of div.
<br/>
<br/>
Here is a example program.
<br/>
<br/>
<textarea name="Name" rows="12" cols="80">
#include<stdlib.h>
#include<stdio.h>
int main(){
int numerator=15,denominator=4;
div_t result;
result=div(numerator,denominator);
printf("Quotieint =%d,\n Reminder=%d",result.quot,result.rem);
}
</textarea> tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-10448001570451994952021-10-15T11:03:00.000-07:002021-10-15T11:03:05.227-07:00bash script to generate fibonacci series
Here is a linux bash script to generate fibonacci series .Fibonacci series is a sequence of numbers where each number is generated by addition of the previous two numbers in the sequence.
<br/>
<br/>
The script asks the user to provide how many numbers of the series have to be generated and prints out the numbers in the fibonacci series as many requested by the user.
<br/>
<br/>
<textarea name="Name" rows="18" cols="80">
#! /bin/bash
num=0
echo "How many numbers in Fibonacci series are to be generated ? "
read num
fib[0]=0
fib[1]=1
fib[2]=1
for mun in `seq 3 $num`
do
fib[$mun]=$((${fib[$mun-1]}+${fib[$mun-2]}))
done
echo "The fibonacci numbers are"
echo ${fib[*]}
</textarea>
<br/>
<br/>
Save the script as fibonacci,sh , open the terminal and run the script using
<br/>
<br/>
<textarea name="Name" rows="8" cols="80">
$ bash fibonacci.sh
How many numbers in Fibonacci series are to be generated ?
6
The fibonacci numbers are
0 1 1 2 3 5 8
</textarea>
<br/>
<br/>
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-12430505067490268242021-09-11T12:32:00.004-07:002021-09-11T12:32:57.921-07:00A look into the /dev/null driverWe must have used the /dev/null to send the unwanted output from the terminal , its like a sinkhole into which we can dump any data and it is lost forever. We can only write into it but never read out of the /dev/null. For example
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
echo "hello" > /dev/null
</textarea>
<br/>
<br/>
The string goes into the /dev/null , but does not get saved in it. If /dev/null is read, it will print nothing.
<textarea name="Name" rows="2" cols="80">
cat /dev/null
</textarea>
<br/>
<br/>
Let us look under the null device and see how this is achivedin the kernel. The null device is a charachater device, which can be noticed by listing it
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Sep 12 00:21 /dev/null
</textarea>
<br/>
<br/>
The first charahcter is "c" which indicates it is a charachter device. Being a charachter driver it should have a read operation and writer file operations mapped to it. These can be found in the file mem.c . The write_null and read_null functions meant to read and write from the null device are written in the file mem.c . Let us look at the write_null
<br/>
<br/>
<textarea name="Name" rows="6" cols="80">
static ssize_t write_null(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
return count;
}
</textarea>
<br/>
<br/>
As can be seen the function does not store any data, but just returns a count of data recevied. Thus any data written into the devices does not get stored in any location and is just lost completely.
<br/>
<br/>
Similarly if we look at the read_null function.
<br/>
<br/>
<textarea name="Name" rows="6" cols="80">
static ssize_t read_null(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
return 0;
}
</textarea>
<br/>
<br/>
We can see that the above function will always return a 0, every time is read and does not really return any data to the user space. Thus reading out of the null driver never produces any output, but the read operation succeeds everytime. tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-24611969565029039262021-08-31T12:15:00.001-07:002021-08-31T12:15:53.662-07:00EOL while scanning string literalThe following error might come in python when working with strings that have a "\" in it.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
EOL while scanning string literal
</textarea>
<br/>
<br/>
This error is generally because of the use of the backslash in a string operation.
For example , consider the string
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
string1="hello \ this \ that"
</textarea>
<br/>
<br/>
If we want to split the string using "\" as the seperator, we can not use
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
string1.split("\")
</textarea>
<br/>
<br/>
The above split command will throw the EOL error. To get around this, we need the escape the special meaning of the "\" by using another "\" preceding it.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
string1.split("\\")
['hello ', ' this ', ' that']
</textarea>
<br/>
<br/>
Using split function by prefixing a "\" with another "\" will ensure that we do not get the EOL error
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-70350619462713729472021-08-17T23:16:00.002-07:002021-08-17T23:16:59.148-07:00VMplayer : make: *** [Makefile:117: vmnet.ko] Error 2 Unable to install all modules. See log for details.A recent update on VMplayer16 version attempted to install the module for vmnet but it was unable to do so broke the vmplayer, with the error message
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
Unable to install all modules. See log for details.
</textarea>
<br/>
<br/>
The log showed an error indicating some issue with the compilation of the vmnet module and was not able to generate the module for it.
<textarea name="Name" rows="10" cols="80">
/tmp/modconfig-8DbDF1/vmnet-only/userif.c:578:13: error: too many arguments to function ‘csum_and_copy_to_user’
[scripts/Makefile.build:287: /tmp/modconfig-8DbDF1/vmnet-only/userif.o] Error 1host-4864| I005: make[2]: *** Waiting for unfinished jobs....
host-4864| I005: make[1]: *** [Makefile:1848: /tmp/modconfig-8DbDF1/vmnet-only] Error 2
host-4864| I005: make: *** [Makefile:117: vmnet.ko] Error 2
</textarea>
<br/>
<br/>
The issue was in the vmplayer version 16.0, the simplest workaround for this is to download the vmplayer 16.1.2 from the site or any newer version avaialble and install the same. This issue has been fixed in the newer versions, and the vmplayer is able to lauch successfully.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-26771109096497787522021-08-13T12:19:00.000-07:002021-08-13T12:19:03.749-07:00Generate Indian Flag on the Linux Terminal Here is a script to generate something close to India Flag on the linux Terminal. The output looks as shown in he figure below .
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl6VdDUz84inMlTAAtTUi1lqhdn5CXKq9rL6U9g3jYFf0787ocQqewho32UU12B6mxVceURPPhd-7fUwqJNSci_-E4T-fCTwe0gEncvy-cMXM5f7ij4GIVVdOwtCjblwzvtrNa5eBculM/s1268/tux_flag.png" style="display: block; padding: 1em 0px; text-align: center;"><img border="0" data-original-height="439" data-original-width="1268" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl6VdDUz84inMlTAAtTUi1lqhdn5CXKq9rL6U9g3jYFf0787ocQqewho32UU12B6mxVceURPPhd-7fUwqJNSci_-E4T-fCTwe0gEncvy-cMXM5f7ij4GIVVdOwtCjblwzvtrNa5eBculM/w640-h222/tux_flag.png" width="640" /></a></div>
<textarea cols="80" name="Name" rows="80">horizontal() {
hrow=$2
hstart=$1
hcols=$3
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
set_color(){
tput setaf 2
}
clear
tput setab 3
for((k=0;k<=7;k++))
do
horizontal 2 $k 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 7
for((k=8;k<=15;k++))
do
horizontal 2 $k 70 " "
done
tput setab 4
for((k=8;k<=15;k++))
do
horizontal 50 $k 80 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 7
for((k=8;k<=15;k++))
do
horizontal 80 $k 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 2
for((j=16;j<=23;j++))
do
horizontal 2 $j 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
</textarea>
<br />
<br />
Save the file as the flag.sh and run it in the terminal, with terminal in the full screen.
<br />
<br />
<textarea cols="80" name="Name" rows="2">$ bash falg.sh
</textarea>
<br />
<br />
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-86759991474021846032021-08-11T09:02:00.000-07:002021-08-11T09:02:11.100-07:00Record Sound or Voice in Ubuntu To record sound using linux/ubuntu we don't need and special softwares, a simple command line tool is available called arecord. One of the simple way to use the command in the terminal as follows.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
$ arecord filename.wav
</textarea>
<br/>
<br/>
The recording is continued as long as Cntrl+C is not pressed, recording infinitely. The recording will get saved in the file named filename.wav
<br/>
<br/>
If the recording needs to be stopped after a specific interval we can use the option -d
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
$ arecord -d 10 filename.wav
</textarea>
<br/>
<br/>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-91900962093316327702021-04-17T20:06:00.000-07:002021-04-17T20:06:00.931-07:00Loading modules automatically on bootLinux kernel loads all the needed modules while booting, but some modules compiled and added later or externally might need to the loaded manually at every boot. Loading of such modules can be automated using the .conf file in /etc/modules-load.d . For example we have a file named cpu-filters.conf in the modules-load.d folder.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
lp
ppdev
parport_pc
</textarea>
<br/>
<br/>
If we look at the modules loaded in the kernel, we can see all these three modules as shown in the figure below
<br/>
<br/>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJnXpBbNKgvi2v1C7aBsIGv0VIy2Ur-cBg0HiuaMt_3KAemA_qvhyphenhyphenkvIh4A_ktCKy9Vd1K7HCEJP8LUcmBPo3zMtvi48K72GOuIq_aAXah4W5r6_gjxNKp-pEAlvSuGgInLJzs7IevNW4/s507/lp_present.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="219" data-original-width="507" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJnXpBbNKgvi2v1C7aBsIGv0VIy2Ur-cBg0HiuaMt_3KAemA_qvhyphenhyphenkvIh4A_ktCKy9Vd1K7HCEJP8LUcmBPo3zMtvi48K72GOuIq_aAXah4W5r6_gjxNKp-pEAlvSuGgInLJzs7IevNW4/s320/lp_present.png"/></a></div>
<br/>
<br/>
Now if we comment out the lp module.
<textarea name="Name" rows="2" cols="80">
# lp
ppdev
parport_pc
</textarea>
<br/>
<br/>
Restart the computer after commenting the lp module and search for the lp module.
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOoO82Bw9JVVNCUp1NBl5fg-As3ve6TL1exJ_4QNjJKfpBA8_sx915e8o-p7uj25Tw39QP4oWwZOIu1HM0C0x83cfnB9STKnVdA6C2p1-qxPva8fm2wLqYYuSpz8cqu2ZFiwhUeytzuQE/s630/lp_missing.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="180" data-original-width="630" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOoO82Bw9JVVNCUp1NBl5fg-As3ve6TL1exJ_4QNjJKfpBA8_sx915e8o-p7uj25Tw39QP4oWwZOIu1HM0C0x83cfnB9STKnVdA6C2p1-qxPva8fm2wLqYYuSpz8cqu2ZFiwhUeytzuQE/s320/lp_missing.png"/></a></div>
<br/>
<br/>
It can be seen the lp is not loaded this time.
<br/>
<br/>
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-32686923472614435592021-03-27T05:41:00.002-07:002021-03-27T05:41:53.127-07:00Script to find if a number is odd or even using the command factor. Here is linux shell script which will find if a number is even or odd using the command factor.
<br />
<br />
<textarea name="Name" rows="18" cols="80">
#!/bin/bash
echo "Enter the number"
read x
res=$(factor $x | grep -c 2)
if [ $res -eq 0 ]
then
echo "The number is odd"
else
echo "The number is even"
fi
</textarea>
<br />
<br />
Save the script as oddEven.sh and execute it using bash.
<br />
<br />
<textarea name="Name" rows="6" cols="80">
$ bash oddEven.sh
Enter the number
32
The number is even
</textarea>
<br />
<br />
The factor command basically lists all the factors of the number, and by using grep we search for 2 using the option -c to count if 2 is present count will be 1 , else it will be 0.
<br />
<br />tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-45824136409010949512021-02-12T09:39:00.002-08:002021-02-12T09:39:55.749-08:00Create screenshot using gimpGimp can be used to take screenshots of the screen, or specific window or regions.
<br />
<br />
Click on File->Create->Screenshot
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqzV66t8_RE6Rnp_wftEWc9WkFeb2lQnwD3EVkmnY81JDiY8iCu0XWfe23vU2XGgcvJNAq11DquB47LPVRCqh44zNJzZ-schTvcVk-tF6InCxLy8I0cN1bdE4ljERwKN0K4wqK14Fh-ww/s1366/gimp_screenshot1.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="768" data-original-width="1366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqzV66t8_RE6Rnp_wftEWc9WkFeb2lQnwD3EVkmnY81JDiY8iCu0XWfe23vU2XGgcvJNAq11DquB47LPVRCqh44zNJzZ-schTvcVk-tF6InCxLy8I0cN1bdE4ljERwKN0K4wqK14Fh-ww/s320/gimp_screenshot1.png"/></a></div>
<br />
<br />
It will pop the following menu. providing the options to either take the screenshot of the active window, or the entire screen or a specific region. It also allows to add delay in seconds to allow us the close the gimp window and open the window of which we want to take the screenshot of.
<br />
<br />
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvdqu8GrtAZCzIOCl5UDD7eJvsBxkssvVitsiVh1wNHaS-AX6ewrDYdriGL-eOZU-slV5K6dutGjA1h0xiFO_XsLMjGqNjFzkWpUHYK89dxyy-qpxoTfSwxDNMYd9hmCs3O1QHuqjMQnM/s456/gimp_screenshot2.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="449" data-original-width="456" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvdqu8GrtAZCzIOCl5UDD7eJvsBxkssvVitsiVh1wNHaS-AX6ewrDYdriGL-eOZU-slV5K6dutGjA1h0xiFO_XsLMjGqNjFzkWpUHYK89dxyy-qpxoTfSwxDNMYd9hmCs3O1QHuqjMQnM/s320/gimp_screenshot2.png"/></a></div>
<br />
<br />
When we select the option of screenshot of a specific region, it allows us to specify delay after which we want to select the region to be taken screenshot of and also delay in seconds after which the screenshot should be taken. So it allows us to get out of the gimp window and make the selection of the area, as well as open another application if screenshot needs to be taken of another application. tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-24274709709647393512021-02-03T10:56:00.000-08:002021-02-03T10:56:48.945-08:00Gimp Hide all dockable windows. While working with gimp, if you want to hide all the dockable toolboxes around it, so that you can concetrate only on the image in the window, we can click on the options windows->Hide Docks as shwown
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcyCDZbmECdPDtLkYO4Wpwj-Tj1noURHBFwmMoi95it07f3WzosR475c7dSpY5DZqB3k0iRDMRaK45N21JcSAzoxT-N9X2dsZmb1FozvyMvBBkrhQJCkxJTU87QSkAWvGJrEfhWcnUq7o/s1366/gimp_hide_docks.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="768" data-original-width="1366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcyCDZbmECdPDtLkYO4Wpwj-Tj1noURHBFwmMoi95it07f3WzosR475c7dSpY5DZqB3k0iRDMRaK45N21JcSAzoxT-N9X2dsZmb1FozvyMvBBkrhQJCkxJTU87QSkAWvGJrEfhWcnUq7o/s320/gimp_hide_docks.png"/></a></div>
<br />
<br />
With all dockable windows hidden we are left with only the image.
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLUgGV2TFMqqeZ6xiFdWXVNNdTsDw04UiqdMmBJeF9zJe6XaPrjwgSWh_vnSLVEWrTMYfOtKneMMR152cXysT-rwPQKyKRsU9xA9lMjE0s89B_Ymf2VwWnymWRDr-M6YRv5ZM4do8Y0Kw/s1299/gimp_hidden_docks.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="701" data-original-width="1299" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLUgGV2TFMqqeZ6xiFdWXVNNdTsDw04UiqdMmBJeF9zJe6XaPrjwgSWh_vnSLVEWrTMYfOtKneMMR152cXysT-rwPQKyKRsU9xA9lMjE0s89B_Ymf2VwWnymWRDr-M6YRv5ZM4do8Y0Kw/s320/gimp_hidden_docks.png"/></a></div>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-6178570795506124422021-01-02T21:46:00.003-08:002021-01-02T23:29:07.705-08:00Llinux Shell Script to check if a file exists Here a linux shell script which can be used to find if a file exists or not at a given location.
<br />
<br />
<textarea name="Name" rows="16" cols="80">
#!/bin/bash
echo "Enter the file name to be find if it exists in the current directory"
echo "OR"
echo "Enter the full path to search for file any other directory"
read name
ls $name 2&>1 /dev/null
if [ $? -gt 0 ]
then
echo "File $name does not exist"
else
echo "File $name exists"
fi
</textarea>
<br />
<br />
Save the file as checkifFileExist.sh and execute it as shown below.
<br />
<br />
<textarea name="Name" rows="6" cols="80">
$ bash checkifFileExist.sh
Enter the file name to be find if it exists in the current directory
OR
Enter the full path to search for file any other directory
</textarea>
<br />
<br />
When prompted enter the file name if you want to check in the current directory or enter the full path to where the presence of the file has to be checked, and the script will show if the file exists or not .
<br />
<br />
<textarea name="Name" rows="2" cols="80">
hello
File hello does not exist
</textarea>
<br />
<br />
We can use the following script if we want to pass the file name to be searched for as a command line argument.
<textarea name="Name" rows="10" cols="80">
#!/bin/bash
ls $1 2&>1 /dev/null
if [ $? -gt 0 ]
then
echo "File $1 does not exist"
else
echo "File $1 exists"
fi
</textarea>
<br />
<br />
Save the file as checkifFileExist.sh and execute it as shown below.
<br />
<br />
<textarea name="Name" rows="2" cols="80">
$ bash checkifFileExist.sh file1
File file1 exists
</textarea>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-45826144170348836412020-12-27T09:51:00.001-08:002020-12-27T09:51:59.087-08:002021 on Linux TerminalHere is a bash script which can be used to create the text 2021 on the terminal using any characher of your choice.
<br />
<br />
<textarea textonly rows="180" cols="70">
#!/bin/bash
#create 2021 on terminal using any user specified character
str_dwn() {
rows=$1
s_start=$2
char=$4
str_st_row=$3
rows_end=$((str_st_row+rows))
for((i=str_st_row;i<rows_end;i++))
do
tput cup $i $s_start
printf "$char "
done
echo""
}
backslash() {
b_st_row=$1
b_st_cols=$2
b_char=$3
b_r_end=$((b_st_row + 5 ))
for((p=b_st_row;p<b_r_end;p++))
do
tput setaf $4
tput cup $p $b_st_cols
printf "$b_char "
((b_st_cols++))
done
echo""
}
forward() {
f_st_row=$1
f_st_cols=$2
f_len=$3
f_char=$4
f_r_end=$((f_st_row + $f_len))
for((i=f_st_row;i<f_r_end;i++))
do
tput cup $i $f_st_cols
printf "$f_char "
((f_st_cols--))
done
echo""
}
horizontal() {
hrow=$2
hstart=$1
hcols=$3
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
half_horizontal() {
hrow=$2
hstart=$1
hcols=$(($3/2))
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
gen_rand() {
num1=$1
if [ $num1 -eq 0 ]
then
temp=$(($RANDOM % 2))
rand=$((temp + 2))
else
temp=$(($RANDOM % 5))
rand=$((temp + num1))
fi
}
two() {
hstart_2=$1
hrow_be=$2
hcols_2=$3
char=$4
color=$5
set_color
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
hstart_2_lo=$start
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
zero() {
set_color
hstart_0=$((f_st_cols_2 +4))
hcols_0=5
horizontal $hstart_0 $hrow_be $hcols_0 "$char"
str_dwn_col_0=$hstart_0
str_dwn_row_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_0 $str_dwn_row_0 "$char"
hstart_0_lo=$((f_st_cols_2 +4))
hcols_0_lo=6
hrow_0_lo=$((hrow_be+6))
horizontal $hstart_0 $hrow_0_lo $hcols_0 "$char"
str_dwn_col_rig_0=$((hstart_0 +5))
str_dwn_row_rig_0=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_rig_0 $str_dwn_row_rig_0 "$char"
}
twoo() {
set_color
set_color
##############################
hstart_2=$((str_dwn_col_rig_0 +2))
hcols_2=6
horizontal $hstart_2 $hrow_be $hcols_2 "$char"
###############################################
st_row_2=$((hrow_be+1))
f_st_cols_2=$((hstart_2+hcols_2))
forward $st_row_2 $f_st_cols_2 5 "$char" $color
######################################################
hstart_2_lo=$hstart_2
hrow_2_lo=$((hrow_be+6))
hcols_2_lo=5
horizontal $hstart_2_lo $hrow_2_lo $hcols_2_lo "$char"
}
one() {
set_color
str_dwn_col_1=$((hstart_2 + 8))
str_dwn_row_1=$((hrow_be))
str_dwn 7 $str_dwn_col_1 $str_dwn_row_1 "$char"
}
five() {
set_color
set_color
#hstart_8=$((str_dwn_col_1 +4))
#hcols_8=5
#horizontal $hstart_8 $hrow_be $hcols_8 "$char"
str_dwn_col_8=$hstart_8
str_dwn_row_8=$((hrow_be + 1))
str_dwn 3 $str_dwn_col_8 $str_dwn_row_8 "$char"
hstart_8_lo=$((f_st_cols_2 +4))
hcols_8_lo=6
hrow_8_lo=$((hrow_be+6))
horizontal $hstart_8 $hrow_8_lo $hcols_8 "$char"
str_dwn_col_rig_8=$((hstart_8 +5))
str_dwn_row_rig_8=$((hrow_be + 1))
str_dwn 6 $str_dwn_col_rig_8 $str_dwn_row_rig_8 "$char"
hstart_8_lo=$((f_st_cols_2 +4))
hcols_8_lo=6
hrow_8_lo=$((hrow_be+3))
horizontal $hstart_8 $hrow_8_lo $hcols_8 "$char"
}
set_color(){
color=$RANDOM
color=$((color%6))
tput setaf $color
}
cols=`tput cols`
mid=$((cols/2))
start=$((mid-16))
echo "What character do you want to use"
read char
#char="*"
tput clear
rows=5
begin_row=2
num_cols=6
two $start $begin_row $num_cols "$char" $color;zero;twoo;one
tput setaf 7
tput cup 9 0
</textarea>
<br />
<br />
Copy the script and save it as 2021.sh. Open a terminal and type
<textarea textonly rows="2" cols="70">
bash 2021.sh
</textarea>
<br />
<br />
It will prompt for the characher which should be used.
<textarea textonly rows="2" cols="70">
What character do you want to use
*
</textarea>
We have entered "*" as the characher, and you should see the output as shown below.
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2rOvPTNlDhgRgHoLj7TyalCFSlyyVNVERn4mbixx0XsiKIHKWNBLyoGJKkiM05DG0jiorGjIDRNXTGrzdUsHIqyBmMgkNcKH-dRfvZAZ7vfWBMzyEC9X196NZB94Uf6M_v6g0MpzZKGQ/s306/2021.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" width="320" data-original-height="164" data-original-width="306" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2rOvPTNlDhgRgHoLj7TyalCFSlyyVNVERn4mbixx0XsiKIHKWNBLyoGJKkiM05DG0jiorGjIDRNXTGrzdUsHIqyBmMgkNcKH-dRfvZAZ7vfWBMzyEC9X196NZB94Uf6M_v6g0MpzZKGQ/s320/2021.png"/></a></div>tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-41011659289239959182020-12-21T06:19:00.000-08:002020-12-21T06:19:42.151-08:00Extracting images from a PDFTo extract images from a pdf document we can use the command
<br />
<br />
<textarea name="Name" rows="2" cols="80">
pdfimages
</textarea>
<br />
<br />
The syntax to use the command is
<textarea name="Name" rows="2" cols="80">
pdfimages -f "first page number" -l "last page number" "file name" "path for images with name"
</textarea>
<br />
<br />
<textarea name="Name" rows="2" cols="80">
pdfimages -f 1 -l 4 test.pdf images
</textarea>
<br />
<br />
The above command will extract the images from page number 1 to page number 4 and the name of the images will be image-000.ppm ,image-001.ppm etc. The default format is ppm if the format of the file is to be changed, png option can be passed.
<br />
<br />
<textarea name="Name" rows="2" cols="80">
pdfimages -f 1 -l 4 -png test.pdf images
</textarea>
<br />
<br />
The above command will extract the images in the png format.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-75388530539730600632020-12-04T09:53:00.000-08:002020-12-04T09:53:33.774-08:00Package inputenc Error: Unicode character Σ (U+03A3) (inputenc) not set up for use with LaTeX.Running Pdflatex with math symbols not put inside proper math block can throw this error
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
Package inputenc Error: Unicode character Σ (U+03A3) (inputenc) not set up for use with LaTeX.</textarea>
<br/>
<br/>
In the above message the sigma symbol is being used outside the math block as shown below.
<textarea name="Name" rows="2" cols="80">
x= Σyi </textarea>
<br/>
<br/>
The solution is to put the equation into the math block, so surround the text with $ symbols and use the sum command which is the latex for sigma.
<br/>
<br/>
<textarea name="Name" rows="2" cols="80">
$x= \sum yi$ </textarea>
<br/>
<br/>
The error should not apper now on the usage of pdflatex .
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0tag:blogger.com,1999:blog-5826231862295491795.post-20976997920722750032020-10-04T21:42:00.001-07:002020-10-04T21:42:50.203-07:00Taking a screenshot from command line in gnomeThe command
<br />
<br />
<textarea name="Name" rows="2" cols="80">
gnome-screenshot
</textarea>
Allows us to cpature screenshot of our screens from the command line itself and it is a pretty flexible commnad too . If just the command is exectued with no arguments, the whole screen is captured and the screenshot gets saved in the folder, with the name having the date and time when it was cpatured.
<br />
<br />
<textarea name="Name" rows="2" cols="80">
~/Pictures
</textarea>d
<br />
<br />
If we want to save the file to with a specific name we can pass the command line option -f , we can also define the path along with the name to change the folder into which it will get saved.
<br />
<br />
<textarea name="Name" rows="2" cols="80">
gnome-screenshot -f ~/Documents/my_screenshot.
</textarea>
<br />
<br />
The above command will save the screenshot in folder Docments under the home folder with the name my_screenshot.
<br />
<br />
The option -c on the other hand, will not save the file at all, instead it copies the screenshot to the clipboard, which we can paste directly into a document or presentation etc.
<br />
<br />
Instea of capturing the full screen, if we need to capture a specific area on the screen we can pass the optinon -a
<br />
<br />
<textarea name="Name" rows="2" cols="80">
gnome-screenshot -a
</textarea>
<br />
<br />
This will allow us to choose the area that has to be captured using our mouse.The -a option combined with -f option will allow us to save the chosen area in the required fodler with the required name.
<br />
<br />
We can also cause the screenshot to be cpatured after a certain delay from the time the command is executed using the option -d along with the delay in seconds.
<br />
<br />
<textarea name="Name" rows="2" cols="80">
gnome-screenshot -d 10
</textarea>
<br />
<br />
The above command will cause a screenshot to be captured after a delay of 10 seconds. The -d and -a option can not be passed at the same time, but -f can be passed with -d to save the screenshot in the required destination.
<br />
<br />
The current active window can be captured using the option -w, and the while capturing the active window, if we do not want the border of the window it can be removed using the option -B.
tuxthinkhttp://www.blogger.com/profile/11642576082677583230noreply@blogger.com0