1

I have been using fifos for controlling mpg123 player, there every-time I need to execute these 3 commands

mkfifo a // create fifo
cat > a & //to run it indefinately
mypid=$! //assign some dummy pid

I want to put this into some script which would execute it at the boot, i wrote a script containing these commands. but it was not working, after some search i got i had to execute it like

. test.sh

manually i can execute it like the above way but automatically how to execute i am struggling.?

EDITED
test.sh
cd /root/work/

now executing this as ./test.sh will not change directory on terminal as it is executed in child process, and executing it as . test.sh will change the directory to /root/work.
I want to execute it as . test.sh through some function/script or anything that i can put at startup and at every boot it runs

Kalu DADA
  • 53
  • 8
  • have you tried `sh /full/path/to/test.sh` ? – Alex Tartan Nov 02 '15 at 11:39
  • do not put "sh" in front do "./full_path_to_script.sh" check if script executable – Noproblem Nov 02 '15 at 11:43
  • yeah, i tried manually i can execute the script like **. test.sh** but i want to execute it at the startup, there it is executing as **test.sh** please not . here. – Kalu DADA Nov 02 '15 at 11:44
  • @Noproblem script i can execute but i want to execute it as . test.sh at the startup but if i put this in /etc/init.d there it is executing as simply test.sh, without the . it is not sourcing and cat and mypid commands has no use. For reference [link](http://www.heapoverflow.me/question-please-help-me-make-this-bash-script-work-29618298) – Kalu DADA Nov 02 '15 at 11:47
  • @Dinesh chaudhary try "source /dir_to_script/test.sh " without dot. What path to test.sh and file who's sourcing? From where do you call your script, and what command trying to do? – Noproblem Nov 02 '15 at 12:03
  • 1
    What is startup? system startup (`/etc/rc.local`), services startup (`/etc/init.d`), gdm/lightdm login (`~/.config/autostart`), bash login (`~/.bashrc`) or something else? My best guess is that you want one of the last 2 cases. It does not make much sense to run these commands at system startup... They could be per-user... – anishsane Nov 02 '15 at 12:13
  • @Noproblem if i do **source /root/work/test/test.sh** it executing, but when i want to execute same by other script so i am having a script file _/root/work/test/test1.sh_ which contains **#!/bin/sh source /root/work/test/test.sh** But source at the start is not having any effects here the command is simply executing like **/root/work/test/test.sh** – Kalu DADA Nov 02 '15 at 12:40
  • @Dinesh chaudhary , so for the first run it's ok? but your other script can't execute? Maybe you should put in function? and call function from other scripts. If you can provide more information, and edit your quoestion – Noproblem Nov 02 '15 at 13:05
  • Check this link: http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-scrip – Noproblem Nov 02 '15 at 13:12
  • @Noproblem edited the question with more details. – Kalu DADA Nov 02 '15 at 13:37
  • @Dinesh chaudhary thanks for edit, you looking for this: http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script . At the end of your ~/.bashrc file add: source /root/work/test/test.sh – Noproblem Nov 02 '15 at 14:36
  • @Noproblem Now if I execute my script as **source /root/work/test/test.sh** perfectly fine but when putting the same line at the end of ~/.bashrc file it's not working same way – Kalu DADA Nov 03 '15 at 10:05
  • @Dinesh chaudhary , maybe ~/.bashrc belong to user - non root, and user can't execute files in /root path, or read it or cd to directory. What output of command `whoami`? – Noproblem Nov 03 '15 at 10:43
  • output is **root** only, cd is working there in ~/.bashrc but _mkfifo /root/work/test/a_ _cat > /root/work/test/a &_ _mypid=$!_ this script doesn't work is it because of some specific commands or any other things – Kalu DADA Nov 03 '15 at 12:19

1 Answers1

1

Since mpg123 they are providing feature for fifo control of the player

instead of executing all the commands mentioned above

just
mpg123 -R --fifo /usr/test/FIFO_NAME

and then send the command to FIFO and it's done.

Kalu DADA
  • 53
  • 8