Please Explain How This Read Command Works

Hi All,

I am new to linux and I am finding difficulties in understanding the below commands.

Please explain what is happening in the below commands.

Code:
IFS="~"
exec 4< $BCP_DIR/cnts.data
while read -ru4 TableName Count CreationDateTime Type AccessDate
do
        . /apps/rmb/prod/scripts/load_datasum.ksh
done
IFS=" "
exec 4<&-


Please explain how this commands flows especially
exec 4< $BCP_DIR/cnts.data & exec 4<&-


Similar Content



No UTMPX Entry, You Must EXEC "login" For The Lowest "shell"

I have this message in Suns 5.10 sparce server ( No UTMPX entry, You must EXEC "login" for the lowest "shell" ) and then I can't access to the server at all . When I write the password the page disappeared . So pls help me how to solve this problem... Thanks a lot

Jamal

No UTMPX Entry, You Must EXEC "login" For The Lowest "shell"

I have this message in Suns 5.10 sparce server " No UTMPX entry, You must EXEC "login" for the lowest "shell" " and then the shell screen disappeared whenever I enter the password , so I can't never login to the server . So pleas help me

Finding In Wrong Order So Cat Is Messed Up

hi guys,

thanks in adv for looking through the long winded post...

i'm trying to cat a bunch of text files together into one, but i'm running into problems and i think it's because of how 'find' is working, but i'm not really sure. here's the command i'm using


Code:
find . -name '*.dat' -exec cat {} \; > out.txt

my data structure looks like

dir1
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir2
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir3
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir4
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir5
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir6
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir7
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir8
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir9
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat
dir10
f1.dat
f2.dat
f3.dat
f4.dat
f5.dat
f6.dat
f7.dat
f8.dat
f9.dat
f10.dat

so I "think" in my cat'd file I'm getting the order like this,

dir1f1
dir1f10
dir1f2
dir1f3
dir1f4
dir1f5
dir1f6
dir1f7
dir1f8
dir1f9
dir2f1
dir2f10
dir2f2
dir2f3
dir2f4
dir2f5
dir2f6
dir2f7
dir2f8
dir2f9
etc....

but maybe it's even worse than this, idk

Find 30 Days Old And Delete Prints Error Msg File Not Found After Deleting It

I have a shell script to find folders which are 25 days older and delete it, and put the deleted folder details into log file like this

Code:
 find /ahome/xxx/$FOLDER -type d -mtime +25  -exec ls -ld {} \;  -exec rm -rf {} \;  >> mylogfile.log

after running this command it deletes the folder and logs the folder deleted. But also print error msg
Code:
find: /ahome/prksh/dir/test: No such file or directory

How to suppress the error msg

"Invalid Magic Number" When Loading Initrd Into GRUB Prompt Bootloader

Hi, I'm pretty new to Linux.

I'm currently working on a project in my Linux Administration class, but have run into a bit of a bump.

I'm tasked with booting Linux (currently using CentOS 7) through the GRUB prompt. I've loaded the kernel, but I'm having an issue with the initrd.

I've tried both of these commands:
"linux /boot/initrd-plymouth.img"
"linux /boot/initramfs-3.10.0-123.el7.x86_64.img"

Neither of these commands have worked. It only returns the message "invalid magic number" for both of the commands. Any ideas on how I can fix this?

Thanks for any help in advance. It should help me understand Linux better!

Bash More Commands In One Function

hello

first year of learning linux and bash script
Now i wrote a bash script with a function.
Today i recieved a email from my teacher that 1 function only can have 1 command and no more then 1?

thats a part of the script

Code:
function tx_unreachable_msg()
{
LOGLINE="[$DATE] no ip service unreachable"
typewriter "$NOIPSERVICE niet bereikbaar" .1
sleep 1 
typewriter "Mail wordt verzonden naar $email" .1
mail -s "NO ip mail error" "$email"<<EOF
dynupdate.no-ip.com niet bereikbaar @ $DATE
EOF
}

it's part dutch part english but the point is that the first LOGLINE is forbidden in the function because i use the functie to send a mail end not to write a logline but that's a part of the command in my case?

So what does this function?
If the no ip service is unreachable then it's write to /etc/var/log/no-ip and after the sleep it's send a simpel mail to the adres in the variabele mail.

i read here at the first line:
Quote:
Shell functions are a way to group commands for later execution using a single name for the group.
so is it true that my function is wrong and so no can someone point me to a website where it's say that more commands are allow in 1 function0

grts b

How To Run An Application After The Boot ?

Hi, i know this could seems like a "simple" question but after a lot fo try i can't seems to make it works, i am stuck on this. I am working on a sbc6000x board, linux 2.6.24, an embedded system.

I am working on a pretty nice project which when called like this run perfectly :
Code:
cd /bin
./apps

(/bin/apps don't works, it must be ./apps from the directory)

After searching a little about the startup i learned about rc.local and created it in /etc/init.d, rc.local look like this :

Code:
#!bin/sh
# /etc/rc.d/rc.local: Local system initialization script.
#

cd /bin
./apps
cd

Sadly it seems it is never called. I was thinking about maybe add cd /bin, /.apps to the end of the etc/profile but i don't know if profile can run command aside from simple scripts call.

Does anyone has an idea on why this don't work or on how i could do this ?

How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!

Please Interpret The Meaning Of This Command

Hi ,

Please explain what the below command means ..


Code:
if grep -c -i Y $INIFILE > /dev/null

I know what is the use of grep, it is used for finding a character or string in a file. But i could not understand the above form of grep command.

I am new to linux so this might be a simple question, but please throw some light on it.


Edited

And also please explain why they are creating a file in null in the below command

Code:
cat /dev/null > $DATA_DIR/$DATAFILE

Would Like To "echo" A Line, "read" Reply, Then Execute The Reply: How In Bash?

Apologies. I've been out of Unix for 14 years, and the gears have rusted. Also, Unix has changed - enough similarities to memory that I'm pretty comfy though.

Glad to see lots of info available via google. However changes are going to take getting used to. Have set up a testbed of 3 nearly identical machines, hoping to make an (at home) private network where I can automate installs and set-ups using NIS and NFS (Similar to work I once did).

Have found useful scripts interspersed with comments, would like to copy and paste them to a bash script that:

Reads the line.
Echos the line.
Reads the reply.
Executes what is typed.

Essentially, by making myself type (or copy & paste) the commands I think I'll become familiar.

Figured I'd use a spreadsheet, select the file, and paste into column B of the spreadsheet. In column A I'd paste:

echo "

and in column C I'd paste:

"

Then I'd cut and paste into a text document, insert the lines:

read A
$A

behind every command necessary to the actual task.

Figured I'd have to escape the ' and ".

Ran a test (test.bash):

#!/bin/bash
for i in `seq 1 10`;
do
echo "Enter a command:"
read A
echo "Trying $A"
$A
done

works fine when I type

ls -alg

but not so when I type

ls -alg | grep dwrx

so I'm wondering if someone has a suggestion?

Thanks for any ideas.