Bash code to create named Pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash code to create named Pipe
# 1  
Old 01-28-2012
Bash code to create named Pipe

Guy's,

I need help with creating a pipe, I found this code online but not exactly sure what different parts are doing.

Will someone be able to help me with explaining what code is doing?

Also what I want is to have everything the same directory. Meaning I am working in directory:
Quote:
Home/users/Bashwork/Testing
I want to keep everything in Testing directory.

Code:
#!/bin/bash

  
  HERE=`uname -n`    # Will I be able to add the directory here 
  THERE=bilbo         # What is this creating?
  echo "starting remote backup to $THERE at `date +%r`"
  # ==> `date +%r` returns time in 12-hour format, i.e. "08:08:34 PM".
  
  e
  rm -rf /pipe
  mkfifo /pipe       # ==> Create a "named pipe", named "/pipe".
  
 #What is this doing too?

  su xyz -c "ssh $THERE \"cat >/home/xyz/backup/${HERE}-daily.tar.gz\" < /pipe"&
  cd /

#This too?

  tar -czf - bin boot dev etc home info lib man root sbin share usr var >/pipe


  exit 0

Thanks
# 2  
Old 01-29-2012
It is making a tar archive on a remote location.

Is that what you want?... If you tell us what you are trying to do, we can cut to solving your problem much faster. For example, do you have to have a named pipe?

Look into the
Code:
mknod  filename_for_pipe p
mkfifo pipename

commands

Last edited by jim mcnamara; 01-29-2012 at 01:53 PM..
# 3  
Old 01-29-2012
I have temporary file and I want to create a backup pipe file which will allow me to process the file without loosing anything.
Quote:
It is making a tar archive on a remote location.
Can I change the remote location to a location that I want?


Is using pipe the right thing when processing temporary files?

Thanks
# 4  
Old 01-30-2012
Quote:
Originally Posted by INHF
Guy's,

I need help with creating a pipe, I found this code online but not exactly sure what different parts are doing.

Will someone be able to help me with explaining what code is doing?

Also what I want is to have everything the same directory. Meaning I am working in directory:
I want to keep everything in Testing directory.

Thanks
Code:
#!/bin/bash
 
 
  HERE=`uname -n`    # Stores the node name of the host server
 
  THERE=<SERVER WHERE YOU WANT TO KEEP THE BACKUP>         #Server on which you want to store the backup
 
 MYDIR=/home/users/Bashwork/Testing
  PIPE=${MYDIR}/pipe
 
  echo "starting remote backup to $THERE at `date +%r`"
  # ==> `date +%r` returns time in 12-hour format, i.e. "08:08:34 PM".
  cd ${MYDIR}
 
  rm -rf ${PIPE}
  mkfifo ${PIPE}       # ==> Create a "named pipe", named "/pipe".
 
#What is this doing too?
 ## Assuming you want to create backup from your own user, USER
 
  su ${USER} -c "ssh $THERE \"cat >/home/xyz/backup/${HERE}-daily.tar.gz\" < ${PIPE}"&
 
 
  cd /
 
#This too?
 
  tar -czf - bin boot dev etc home info lib man root sbin share usr var >${PIPE}
 
## This is writing the new tar ball (backup of above mentioned folder) and writing on the PIPE
 
 
  exit 0

This User Gave Thanks to knight_eon For This Post:
# 5  
Old 01-30-2012
Quote:
HERE=`uname -n` # Stores the node name of the host server

THERE=<SERVER WHERE YOU WANT TO KEEP THE BACKUP> #Server on which you want to store the backup
Do I need to store node name of the host server?

Can I keep the backup in the same directory that I am working on?

Thank you all again
# 6  
Old 01-30-2012
Quote:
Originally Posted by INHF
Do I need to store node name of the host server?

Can I keep the backup in the same directory that I am working on?

Thank you all again

If you want to keep the backup in the same directory and that means same server, why u want to create pipes and all?

It can be easily accomplish by simple tar and gzip command.

it will be much easier doing this:

Code:
#!/bin/bash
 
  HERE=`uname -n`    # Stores the node name of the host server
 
 MYDIR=/home/users/Bashwork/Testing
  echo "starting backup at `date +%r`"
  # ==> `date +%r` returns time in 12-hour format, i.e. "08:08:34 PM".
  
  TARBALL="${MYDIR}/${HERE}-daily.tar.gz"
  
cd /
 
#This too?
 
  tar -czf - bin boot dev etc home info lib man root sbin share usr var  | gzip -9c - >${TARBALL}
 
 
  exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Named pipe hanging?

Ok, I can't seem to figure this out or find anything on the web about this. I'm on Sun Solaris, UNIX. I have the following test script: #!/bin/ksh touch test.file LOG=./tmp.log rm -f ${LOG} PIPE=./tmp.pipe mkfifo ${PIPE} trap "rm -f ${PIPE}" EXIT tee -a ${LOG} < ${PIPE} & ... (17 Replies)
Discussion started by: Ditto
17 Replies

2. Shell Programming and Scripting

Named pipe performance

Hi, I am getting data into a Named pipe. Does Named pipe have any size restriction; I know it does not have any storage and it just passes on the data to the next process. I want to know, if there will be a difference in the Named pipe performance if the data input is more. (I am using DB2... (1 Reply)
Discussion started by: sudvishw
1 Replies

3. Shell Programming and Scripting

pipe to file named with date

I would like to pipe (redirect ? - what is the right term?) the output of my script to a file named with the current date. If I run this at a command prompt: date +'%Y%m%d" ...it returns "20110429" OK, that's good... so I try: ./script.sh > "'date +%Y%m%d'.csv" I get a file... (1 Reply)
Discussion started by: landog
1 Replies

4. UNIX for Advanced & Expert Users

will a named pipe always be size 0 on filesystem?

I did cat < myFile >> myPipe I was hoping that if I did ls -l, myPipe would now be holding the contents of myFile, and would be the same size. But it was 0. Also strange was that when I did the command above, cat did not return control back to the shell. Why? thanks (4 Replies)
Discussion started by: JamesByars
4 Replies

5. UNIX for Dummies Questions & Answers

fifo or named pipe working?

Can someone explain to me the working of fifo() system call using simple C programs so that I can implement them in the UNIX environement? (1 Reply)
Discussion started by: lvkchaitanya
1 Replies

6. UNIX for Dummies Questions & Answers

Named Pipe contents to a file

I want to copy the contents of a named pipe to a file. I have tried using: cat pipe.p >> transcript.log but I have been unsuccessful, any ideas? (4 Replies)
Discussion started by: carl_vieyra
4 Replies

7. UNIX for Dummies Questions & Answers

Named PIPE

Gurus, I've a File Transaction Server, which communicates with other servers and performs some processing.It uses many Named PIPE's. By mistake i copied a named PIPE into a text file. I heard that PIPE files shouldn't be copied.Isn't it? Since it's a production box, i'm afraid on... (2 Replies)
Discussion started by: Tamil
2 Replies

8. UNIX for Advanced & Expert Users

named pipe with persistent buffer

Hey folks, i need communicate between 2 processes in a reliable manner. The information delivery has to be guarenteed. I thought about proc 2 sending a signal to proc 1 when information has being written to disc and wirte() has been verified (sync/flush). The IPC method for the data is named... (4 Replies)
Discussion started by: heck
4 Replies

9. Programming

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666) func. It then opens the pipe using open func - fd = open... (2 Replies)
Discussion started by: sharanbr
2 Replies

10. UNIX for Advanced & Expert Users

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666);) func. It then opens the pipe using open func - fd =... (1 Reply)
Discussion started by: sharanbr
1 Replies
Login or Register to Ask a Question