1

I am trying to copy a file on reboot as raspberry pi deletes my .asoundrc file every time. I have a copy of the file saved and a shell script I wrote. The shell script works, but I cannot get it to run in crontab. According to

Code in script named copyASoundRC.sh

#!/bin/bash
cp '/home/sox/asound data/.asoundrc' '/home/sox'

attempted code in crontab

@reboot bash "/home/sox/asound\ data/copyASoundRC.sh"

Any help is greatly appreciated

ps this is a repost from the Raspbery Pi exchange, they said it did not belong there. Please don't get angry for that.

Edit 1 based on @Seamus answer

#!/bin/bash
cp /home/sox/asoundData/.asoundrc /home/sox

@reboot /home/sox/asoundData/copyASoundRC.sh >> /home/sox/mylogfile.txt 2>&1

There are no errors in mylogfile.txt, but it still does not work

4
  • Check out unix.stackexchange.com/questions/109804/…
    – RonJohn
    Mar 30, 2023 at 18:53
  • 1
    I checked to see if cron reboot exists using what is suggested in the chain '@reboot echo "hi" > /home/sox/reboot.txt 2>&1 ' @RonJohn and it works. but still no copy action
    – Collin
    Mar 30, 2023 at 19:22
  • @Peregrino69 deleted, thank you for reminder. The last bit of your comment is cut off, about pointing something out. I am guessing it is about more detail. The issue is, there is not more to add. I created the sh file, which works. I added it to cron on '@restart' it does not
    – Collin
    Mar 30, 2023 at 19:31
  • 1
    Use quoting with " or backslash-escaping, but not both.
    – Jim L.
    Mar 30, 2023 at 19:35

1 Answer 1

0

It appears you may have mangled your script, and your crontab entry...

  • why do you have a space between asound and data in cp '/home/sox/asound data/.asoundrc' '/home/sox'??
  • why do you have a back-slash in the crontab entry??
  • where exactly is the folder you refer to as data??

Assuming the folder data is actually located at /home/sox/asound/data try this for your script & crontab entries:

#!/bin/bash
cp /home/sox/asound/data/.asoundrc /home/sox
@reboot sleep 60; /home/sox/asound/data/copyASoundRC.sh >> /home/sox/mylogfile.txt 2>&1

This (assuming that's the correct location for your copyASoundRC.sh script) will re-direct (>>) stderr and stdout to a logfile to help you with troubleshooting.

6
  • So I used your code to modify mine (no idea why I put a space in the file name) so it now reads as follows #!/bin/bash cp /home/sox/asoundData/.asoundrc /home/sox `@reboot /home/sox/asoundData/copyASoundRC.sh >> /home/sox/mylogfile.txt 2>&1 There are no errors now, but it still does not work (Originally there were errors, thus change to no space)
    – Collin
    Mar 30, 2023 at 19:49
  • Just thinking about it, it may be caused by the same problem that I am doing this for. asound for me is being deleted, so I am trying to put it back. Maybe it is being deleted after I move it as well?
    – Collin
    Mar 30, 2023 at 20:04
  • @Collin: Coupla' things: 1. When I read your question, I wondered why this file was being deleted; i.e. are you sure you've set this asound thing up properly?? 2. Have you looked at /home/sox/mylogfile.txt for any clues?? It could in fact be that your file is being deleted if the deletion action takes place after the @reboot script... that depends on when it's being deleted. You could try copying the file to a different location where it can't be found by asound?
    – Seamus
    Mar 30, 2023 at 20:14
  • @Collin: To avoid a process that deletes your file after @reboot runs, try adding a sleep statement to your crontab entry (see the edit in my answer).
    – Seamus
    Mar 30, 2023 at 20:22
  • 1
    Thank you so much for this! It now works! In Raspberry Pi, they recently swapped to a new audio thing, pulseAudio, dumping Alsa. Even though both are still in there, this file kept on being deleted, but I need it to amplify a mic input due to pulseAudio not having this yet. Thank you again for the delay. That fixed my issue!
    – Collin
    Mar 30, 2023 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .