# Create file in $PBS\_O\_WORKDIR

**URL:** <https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452>\
**Category:** Users/Site Administrators\
**Created:** [February 23, 2023, 6:08am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452 "2023-02-23T06:08:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhushan27](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@bhushan27](https://community.openpbs.org/u/bhushan27)\
**Post date:** [February 23, 2023, 6:08am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/1 "2023-02-23T06:08:14Z")

</div>

Hello,  
I want to create file in $PBS\_O\_WORKDIR few minutes before specified walltime exceeds.

anyone have idea about above query please let me know.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [February 23, 2023, 6:02pm UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/2 "2023-02-23T18:02:45Z")

</div>

> [@bhushan27](#):
>
> I want to create file in $PBS\_O\_WORKDIR few minutes before specified walltime exceeds.

1. server periodic hook or cronjob

2. implement some kind of timer within the script, when it is about to hit the 98% threshold of your requested walltime , then write a file.

---

<div class="post-metadata">

**Author:** ![bhushan27](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@bhushan27](https://community.openpbs.org/u/bhushan27)\
**Post date:** [March 6, 2023, 7:13am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/4 "2023-03-06T07:13:56Z")

</div>

@adarsh Thank you for possible solutions,

1. If i go with hooks, how we can implent this hooks for specific jobs instead of all jobs on cluster.

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [March 6, 2023, 7:47am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/5 "2023-03-06T07:47:37Z")

</div>

> [@bhushan27](#):
>
> 1. If i go with hooks, how we can implent this hooks for specific jobs instead of all jobs on cluster.

Specific jobs needs to be tagged for this , requesting

- for example specific user or list of users  
– for example specific software or list of softwares  
– for example specific queue or queue(s)

---

<div class="post-metadata">

**Author:** ![bhushan27](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@bhushan27](https://community.openpbs.org/u/bhushan27)\
**Post date:** [March 7, 2023, 5:39am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/6 "2023-03-07T05:39:13Z")

</div>

And can I fetch job\_ib in submission script after qsub command, As right now I’m trying to echo $PBS\_JOBID but it is showing my remote session jobid through which I’m submitting my job.

---

<div class="post-metadata">

**Author:** ![speleolinux](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@speleolinux](https://community.openpbs.org/u/speleolinux)\
**Post date:** [March 8, 2023, 6:23am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/7 "2023-03-08T06:23:47Z")

</div>

Hi  
A hook is the best way but for a quick and dirty way you could implement it using bash within the submission script:

1. At the start of the PBS sub script get the system time, add 95% of walltime to get the time at which to create the directory. This can be done using bash arithmetic.
2. Set a user cron job to create the directory at that time.
3. The rest of the submission script is your normal commands.

A hack but it would probably work with little effort.  
Might be helpful: [shell - How to create a cron job using Bash automatically without the interactive editor? - Stack Overflow](https://stackoverflow.com/questions/878600/how-to-create-a-cron-job-using-bash-automatically-without-the-interactive-editor)  
Mike

---

<div class="post-metadata">

**Author:** ![bhushan27](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@bhushan27](https://community.openpbs.org/u/bhushan27)\
**Post date:** [April 4, 2023, 5:15am UTC](https://community.openpbs.org/t/create-file-in-pbs-o-workdir/3452/8 "2023-04-04T05:15:48Z")

</div>

@speleolinux @adarsh Actually i created script and merged this script with job submission script but now i stuck on 1 things,

1. How we can get start time of queued job right after job submission, as using qstat -f we can’t get start time until job gets start execution.
