34

This is a new one for me: What does this error indicate?

  /usr/bin/perl: bad interpreter: Text file busy

There were a couple of disk-intensive processes running at the time, but I've never seen that message before—in fact, this is the first time that I can remember getting an error when trying to run a Perl script. After a few seconds of waiting, I was able to run it, and haven't seen the issue since, but it would be nice to have an explanation for this.

Running Ubuntu 9.04, file system is ext3.

cjm
  • 61,471
  • 9
  • 126
  • 175
chris
  • 36,094
  • 53
  • 157
  • 237

6 Answers6

27

I'd guess you encountered this issue.

The Linux kernel will generate a bad interpreter: Text file busy error if your Perl script (or any other kind of script) is open for writing when you try to execute it.

You don't say what the disk-intensive processes were doing. Is it possible one of them had the script open for read+write access (even if it wasn't actually writing anything)?

kasperd
  • 1,952
  • 1
  • 20
  • 31
cjm
  • 61,471
  • 9
  • 126
  • 175
  • That sounds reasonable - I was working on the script, and this happened just as I saved it and then tried running it. – chris Sep 06 '09 at 15:47
  • 3
    So probably the "disk-intensive process" didn't do anything to your script directly, but it kept the disk busy enough that your stalled while writing out the script and kept it open for several seconds. – hobbs Sep 06 '09 at 22:21
  • That's what I'm thinking - it seems to make sense in any case. – chris Sep 08 '09 at 21:21
  • Sorry, I know you understood what I meant, but typos bug me. I meant "your editor" above of course :) – hobbs Sep 10 '09 at 06:07
  • 1
    This can mean that either the script is being written to, _or_ that the interpreter itself is being written to -- the same error happens in either case. – Charles Duffy May 17 '12 at 15:33
  • Kinda weird that this isn’t considered a kernel bug. – tchrist Sep 30 '12 at 21:53
  • @tchrist, the strange error message, or the fact that it won't let you run a script while it's being written to? – cjm Sep 30 '12 at 22:04
  • I think running a half-written script would lead to bugs even more mysterious than this error message. – cjm Sep 30 '12 at 22:10
  • 1
    Thanks. A coworker had the same problem. It turned out that the graphical FTP client he used for uploading the scripts to the server was still had a grasp on the files. Once I closed the FTP conection the I was able to run the scripts. – Tulains Córdova Apr 26 '16 at 19:36
  • in my case the issue was that I had the file open for editing in Visual Studio Code, from another computer (via a Samba share). So it might also be something on another computer coming in over a network share, especially an IDE. – Professor Falken Mar 20 '23 at 23:32
7

This happens because the script file is open for writing, possibly by a rogue process which has not terminated.

Solution: Check what process is still accessing the file, and terminate it.

Eg:

# /root/wordpress_plugin_updater/updater.pl --wp-path=/var/www/virtual/joel.co.in/drjoel.in/htdocs
-bash: /root/wordpress_plugin_updater/updater.pl: /root/perl/bin/perl: bad interpreter: Text file busy

Run lsof (list open files command) on the script name:

# lsof | grep updater.pl
sftp-serv 4416            root    3r      REG            144,103    11043   33046751 /root/wordpress_plugin_updater/updater.pl

Kill the process by its PID:

kill -9 4416

Now try running the script again. It works now.

# /root/wordpress_plugin_updater/updater.pl --wp-path=/www/htdocs
Wordpress Plugin Updater script v3.0.1.0.
Processing 24 plugins from
Joel G Mathew
  • 7,561
  • 15
  • 54
  • 86
3

If the script was edited in Windows, or any other OS with different "native" line endings, it could be as simple as a CR(^M) "hiding" at the end of the first line. Vi improved can be set up to hide this non native line ending. In my case I simply re-typed the offending first line in VI and the error went away.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Linux User
  • 31
  • 1
2

This always has to do with the perl interpreter (/usr/bin/perl) being inaccessible. In fact, it happens when a shell script is running or awk or whatever is on the #! line at the top of the script.

The cause can be many things ... perms, locked file, filesystem offline, and on and on.

It would obviously depend on what was happening at the exact moment you ran it when the problem occured. But I hope the answer is what you were looking for.

Rap
  • 6,851
  • 3
  • 50
  • 88
  • 1
    The error message "text file busy" has a specific meaning, and wouldn't be caused by any of the issues you mentioned. –  Sep 05 '09 at 23:10
  • 1
    @duskwuff, care to elaborate? Can you share your wisdom with the rest of us? (btw, my research says exactly what I was sharing). – Rap Sep 05 '09 at 23:32
  • 2
    @duskwuff the specific meaning is _exactly_ what this answer describes. Try it yourself -- open /usr/bin/perl for append, and try to run a perl script. Yes, "text file" is a little misleading, but that's what the error has been standardized as for decades. – Charles Duffy May 17 '12 at 15:30
2

If you are using gnu parallel and you see this error then it may be because you are streaming a file in from the same place that you are writing the file out...

0

I had this same issue and grepping to see what was using the file didnt work. turns out i just needed to restart the droplet and viola script now works.